Home > Back-end >  Two methods from UserDefaults.standard
Two methods from UserDefaults.standard

Time:01-13

everybody, tell me by UserDefaults class, methods: 1)

open func setValue(_ value: Any?, forKey key: String)

and 2)

open func set(_ value: Any?, forKey defaultName: String) 

Identical? Just one added as an extension to NSObject, and the other in UserDefaults itself, which is inherited from NSObject?

CodePudding user response:

The one which is on the NSObject seems to be a KVC (key value coding) method and does not have any relation to NSUserDefaults. So you need the second one when working with NSUserDefaults

CodePudding user response:

func setValue(_ value: Any?, forKey key: String) is for enter image description here

enter image description here

enter image description here

  •  Tags:  
  • Related