Swiftpack.co - Package - ios-developer-busan/Preferences

Preferences

Usage

  1. Create Key Type
enum PreferencesKey: String {
    case version
}
  1. Using by property wrapper
@Preferences(key: PreferencesKey.version)
var version: String?

Value Transformer

extension PreferencesTransformer where T: Credential {
    static var credentialTransformer: PreferencesTransformer {
        PreferencesTransformer { (credential) -> Data? in
            guard let credential = credential else { return nil }

            return try? NSKeyedArchiver.archivedData(withRootObject: credential, requiringSecureCoding: true)
        } decode: { (value) -> T? in
            guard let value = value as? Data else { return nil }

            return try? NSKeyedUnarchiver.unarchivedObject(ofClass: T.self, from: value)
        }
    }
}


@Preferences(key: PreferencesKey.credential, transformer: .credentialTransformer)
var credential: Credential?

Github

link
Stars: 1

Dependencies

Used By

Total: 0