All Projects → nmdias → Defaultskit

nmdias / Defaultskit

Licence: mit
Simple, Strongly Typed UserDefaults for iOS, macOS and tvOS

Programming Languages

swift
15916 projects
swift4
162 projects

Projects that are alternatives of or similar to Defaultskit

Persistencekit
Store and retrieve Codable objects to various persistence layers, in a couple lines of code!
Stars: ✭ 121 (-90.99%)
Mutual labels:  userdefaults, tvos
L10n Swift
Localization of the application with ability to change language "on the fly" and support for plural form in any language.
Stars: ✭ 177 (-86.82%)
Mutual labels:  swift-framework, tvos
Webmidikit
Simplest MIDI Swift library
Stars: ✭ 100 (-92.55%)
Mutual labels:  swift-framework, tvos
Flightanimator
Advanced Natural Motion Animations, Simple Blocks Based Syntax
Stars: ✭ 588 (-56.22%)
Mutual labels:  swift-framework, tvos
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+176.25%)
Mutual labels:  swift-framework, tvos
swift-standard-clients
Client declarations and live implementations for standard iOS managers
Stars: ✭ 28 (-97.92%)
Mutual labels:  tvos, userdefaults
Contentful.swift
A delightful Swift interface to Contentful's content delivery API.
Stars: ✭ 132 (-90.17%)
Mutual labels:  swift-framework, tvos
ios-watchos-tvos-macos-resources
Updated list of Swift frameworks and libraries for iOS, watchOS, tvOS and macOS.
Stars: ✭ 58 (-95.68%)
Mutual labels:  tvos, swift-framework
Userdefaultsstore
Why not use UserDefaults to store Codable objects 😉
Stars: ✭ 416 (-69.02%)
Mutual labels:  userdefaults, tvos
Parade
Parallax Scroll-Jacking Effects Engine for iOS / tvOS
Stars: ✭ 754 (-43.86%)
Mutual labels:  swift-framework, tvos
Renative
🚀🚀🚀Build universal cross-platform apps with React Native. Includes latest iOS, tvOS, Android, Android TV, Android Wear, Web, Tizen TV, Tizen Watch, Tizen Mobile, LG webOS, macOS/OSX, Windows, KaiOS, FirefoxOS Firefox TV platforms
Stars: ✭ 1,199 (-10.72%)
Mutual labels:  tvos
Popcorntimetv
Popcorn Time for Apple TV 4, iPhone and iPad
Stars: ✭ 1,216 (-9.46%)
Mutual labels:  tvos
Literoute
LiteRoute is easy transition for your app. Written on Swift 4
Stars: ✭ 90 (-93.3%)
Mutual labels:  swift-framework
Ecno
Ecno is a task state manager built on top of UserDefaults in pure Swift 4.
Stars: ✭ 92 (-93.15%)
Mutual labels:  userdefaults
Markdowngenerator
Swift library to programmatically generate Markdown output and files
Stars: ✭ 76 (-94.34%)
Mutual labels:  swift-framework
Extendable
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.
Stars: ✭ 88 (-93.45%)
Mutual labels:  tvos
Loadingshimmer
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
Stars: ✭ 1,180 (-12.14%)
Mutual labels:  swift-framework
Mothership
iTunes Connect Library inspired by FastLane
Stars: ✭ 72 (-94.64%)
Mutual labels:  tvos
Articles
Articles for NSHipster.com
Stars: ✭ 1,166 (-13.18%)
Mutual labels:  tvos
Mixpanel
Unofficial Swift Mixpanel client
Stars: ✭ 93 (-93.08%)
Mutual labels:  tvos

DefaultsKit

cocoapods compatible carthage compatible language swift

简体中文

DefaultsKit leverages Swift 4's powerful Codable capabilities to provide a Simple and Strongly Typed wrapper on top of UserDefaults. It uses less than 70 lines of code to acomplish this.

Installation >> instructions <<

Usage

Instantiate, or get a shared instance of Defaults

let defaults = Defaults() // or Defaults.shared

Then:

// Define a key
let key = Key<String>("someKey")

// Set a value
defaults.set("Codable FTW 😃", for: key)

// Read the value back
defaults.get(for: key) // Output: Codable FTW 😃

Check if a key has a value:

if defaults.has(key) { 
    // Do your thing
}

If you just need to know that a key/value pair exists, without actually using the value, use the has() method instead of the optional get(for:key). For complex objects it will prevent any unnecessary deserialization.

Implicit Member Expression

You can find a convenience wrapper for your keys by extending DefaultsKey. This allows you use Implicit Member Expression:

// Extend with a custom key
extension DefaultsKey {
    static let someKey = Key<String>("someKey")
}

// Then use it like this
defaults.set("Some key", for: .someKey)
defaults.get(for: .someKey) // Output: Some key

Complex objects

To store a complex object just conform to the Codable protocol:

struct Person: Codable {
    let name: String
    let age: Int
}

Then:

// Create a key
let key = Key<Person>("personKey")

// Get an instance of your Codable conforming enum, struct or class
let person = Person(name: "Bonnie Greenwell", age: 80)

// Set the value
defaults.set(person, for: key)

And finally:

// Read it back
let person = defaults.get(for: key)
person?.name // Bonnie Greenwell
person?.age  // 80

Nested Objects

You can also use nested objects as long as they conform to the Codable protocol:

enum Pet: String, Codable {
    case cat
    case dog
}

struct Person: Codable {
    let name: String
    let pets: [Pet]
}

// Get a Codable conforming instante
let person = Person(name: "Claire", pets: [.cat])

// Set the value
defaults.set(person, for: key)

// And read it back
let person = defaults.get(for: key)
person?.name        // Claire
person?.pets.first  // cat

License

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

Help Wanted

Review/Translate README.zh-CN.md to Chinese

Chinese is the #1 spoken language in the world and I'd love to have DefaultsKit be more inclusive, unfortunately I don't speak Chinese. If you know chinese, and would like to help out, please see issue #1

Thank you 🙏

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].