All Projects → zolomatok → Johnny

zolomatok / Johnny

Licence: other
Melodic Caching for Swift

Programming Languages

swift
15916 projects
objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Johnny

swift-standard-clients
Client declarations and live implementations for standard iOS managers
Stars: ✭ 28 (-22.22%)
Mutual labels:  caching, tvos, watchos
KeyboardKitPro
KeyboardKit Pro extends KeyboardKit with pro features.
Stars: ✭ 42 (+16.67%)
Mutual labels:  tvos, watchos
OpenAPI-Swift
KKBOX Open API Swift Developer SDK for iOS/macOS/watchOS/tvOS
Stars: ✭ 13 (-63.89%)
Mutual labels:  tvos, watchos
SwiftRadix
Easily convert integers to binary/hex/octal strings and back again with clean functional syntax.
Stars: ✭ 34 (-5.56%)
Mutual labels:  tvos, watchos
SwiftBuilder
SwiftBuilder is a fast way to assign new value to the property of the object.
Stars: ✭ 26 (-27.78%)
Mutual labels:  tvos, watchos
SwiftKit
SwiftKit adds extra functionality to the Swift programming language.
Stars: ✭ 47 (+30.56%)
Mutual labels:  tvos, watchos
data-field
A SwiftUI view that wraps a text field to only accept specific data.
Stars: ✭ 13 (-63.89%)
Mutual labels:  tvos, watchos
wwdc2018
You read my developer triceraptus migration notes from dub dub dc 2018
Stars: ✭ 48 (+33.33%)
Mutual labels:  tvos, watchos
tracelog
TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.
Stars: ✭ 52 (+44.44%)
Mutual labels:  tvos, watchos
IrregularGradient
Create animated irregular gradients in SwiftUI.
Stars: ✭ 127 (+252.78%)
Mutual labels:  tvos, watchos
Dots
Lightweight Concurrent Networking Framework
Stars: ✭ 35 (-2.78%)
Mutual labels:  tvos, watchos
RFKit
Toolkit for daily Cocoa development. Since 2012.
Stars: ✭ 20 (-44.44%)
Mutual labels:  tvos, watchos
WWDCNotes
WWDCNotes.com content
Stars: ✭ 343 (+852.78%)
Mutual labels:  tvos, watchos
SwiftCurrent
A library for managing complex workflows in Swift
Stars: ✭ 286 (+694.44%)
Mutual labels:  tvos, watchos
articles-ko
Articles for NSHipster.co.kr
Stars: ✭ 18 (-50%)
Mutual labels:  tvos, watchos
Tesla-API
A iOS, macOS, watchOS and tvOS framework written in Swift to communicate with Teslas vehicle API
Stars: ✭ 32 (-11.11%)
Mutual labels:  tvos, watchos
stinsen
Coordinators in SwiftUI. Simple, powerful and elegant.
Stars: ✭ 563 (+1463.89%)
Mutual labels:  tvos, watchos
Outlaw
JSON mapper for macOS, iOS, tvOS, and watchOS
Stars: ✭ 24 (-33.33%)
Mutual labels:  tvos, watchos
Orchard
Device identification in Swift and Objective-C for iOS, watchOS, and tvOS.
Stars: ✭ 15 (-58.33%)
Mutual labels:  tvos, watchos
QuoteKit
A framework to use the free APIs provided by https://quotable.io
Stars: ✭ 17 (-52.78%)
Mutual labels:  tvos, watchos

Logo

platform license

Johnny is a generic caching library written for Swift 4.

Features

Johnny can cache any model object that conforms to the Cachable protocol.

  • Out-of-the-box support:
    • String, Bool, Int, UInt, Int64, UInt64, Float, Double
    • URL, Data, Date
    • UIImage, UIColor by wrapping them in an Image or Color wrapper class respectively
    • Arrays, Dictionaries and Sets of the above
  • Multiplatform, supporting iOS, macOS, tvOS & watchOS
  • First-level memory cache using NSCache
  • Second-level LRU disk cache
  • Disk access in background thread (always when saving, optionally when fetching)
  • Syncronous & Asynchronous API support
  • Automatic cache eviction on memory warnings & disk capacity reached
  • Unit tested
  • Concise, well-structured code to encourage contributions

Extra ❤️ for images:

  • func setImageWithURL extension on UIImageView, UIButton & NSImageView, optimized for cell reuse

Usage

Caching

Johnny.cache(user, key: "LocalUser")

let imgage = UIImage(named: "awesomeness")
Johnny.cache(Image(image), key: "Image") // Caching a UIImage. UIColor objects must be wrapped in the Color wrapper class the same way.

// You can flag a value to be stored in the Library instead of the Caches folder if you don't want it to be automatically purged:
Johnny.cache(Date(), key: "FirstStart", library: true)

Pulling

// The type of the retrived value must be explicitly stated for the compiler.
let date: Date? = Johnny.pull("FirstStart")

// If you know you are retrieving a large object (> 1.5 MB) you can do it asynchronously
Johnny.pull("4KImage") { (image: Image?) in
    let img = image.uiImage()
}

Removing

Johnny.remove("LocalUser")

Examples

Collections

You can cache any collection of items conforming to the Storable protocol (most standard library data types already do)

let array: [String] = ["Folsom", "Prison", "Blues"]
let stringSet: Set<String> = ["I've", "been", "everywhere"]
// In case of dictionaries, the value must explicitly conform to Storable (so [String: AnyObject] does not work, while [String: Double] does)
let dictionary: [String: String] = ["first": "Solitary", "second": "man"]

Johnny.cache(array, key: "folsom")
Johnny.cache(stringSet, key: "everywhere")
Johnny.cache(dictionary, key: "solitary")

Custom types

Due to current Swift limitations, since the Storable protocol has an associatedType, conformance must be added through an extension. class User: Storable will not work.

struct User {
    
    enum Badassery: String { case Total }
    
    var name: String?
    var uid: Int
    var badassery: Badassery
}


extension User: Storable {
typealias Result = User

static func fromData(data: NSData) -> User.Result? {
    let dict = try! NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions()) as! [NSObject: AnyObject]

    let user = User()
    user.uid = dict["identification"] as! Int
    user.name = dict["name"] as? String
    user.badassery = Badassery(rawValue: dict["badassery"] as! String)!
    return user
}

func toData() -> NSData {
    let json = ["identification": uid, "name": name, "badassery": badassery.rawValue]
    return try! NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions())
    }
}

Using it with Johnny:

let lily = User(name: "Lily", uid: 84823682, badassery: .Total)
Johnny.cache(lily, key: "Lily")

let cachedLily: User = Johnny.pull("Lily")

Requirements

  • iOS 8.0+
  • macOS 10.10+
  • tvOS 9.0+
  • watchOS 2.0+
  • Swift 4.0

Install

CocoaPods

pod 'Johnny'

Carthage

github "zolomatok/Johnny"

Manual

  • Clone the project
  • Select the scheme (platform) and build
  • Drag Johnny.framework to your project
  • In the project settings under your target's General tab, scroll down and add Johhny to the Embedded Binaries section if it's not already added.

Attribution

I'd like to thank the creators of Pantry and Haneke as those projects provided much of the inspiration and some code. Johnny was dreamed up to be the best of both worlds.

License

Johnny is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].