jrendel / SwiftKeychainWrapper

A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.
MIT License
1.59k stars 339 forks source link

Problem with set(...) in template #163

Open chnbr opened 3 years ago

chnbr commented 3 years ago

Hi,

I am using the set() function in a template like this:

@propertyWrapper
struct UserDefault<T> {
  let key: String
  let defaultValue: T

  //let defaults = KeychainWrapper.standard // this gives compiler error "No exact matches in call to instance 'set'"
  let defaults = UserDefaults.standard // this works OK

  init(_ key: String, defaultValue: T) {
    self.key = key
    self.defaultValue = defaultValue
  }

  var wrappedValue: T {
    get {
      return defaults.object(forKey: key) as? T ?? defaultValue
    }
    set {
      defaults.set(newValue as T , forKey: key)
    }
  }
}

When using UserDefaults the code compiles, when using KeychainWrapper it does not. Could you please have a look into that issues ?! Thanks and regards

Christian