Skip to main content

What is the differentdifference between object(forKey:) and value(forKey:) in UserDefaults?

deleted 15 characters in body; edited title
Source Link
Ennabah
  • 2.6k
  • 2
  • 24
  • 40

I've set some user defaults using let userDefaults = UserDefaults.standard, and when I'm retrieving them, I can use any of these:

let userDefaults = UserDefaults.standard jobTextField.text = userDefaults.object(forKey: "job") as? String

OR I can use

let userDefaults = UserDefaults.standard jobTextField.text = userDefaults.value(forKey: "job") as? String

Which in what case this will has noa difference.? It'd be great to know when I can'tcan NOT use one of them.

Thanks a lot :)

I've set some user defaults, and when I'm retrieving them, I can use

let userDefaults = UserDefaults.standard jobTextField.text = userDefaults.object(forKey: "job") as? String

OR I can use

let userDefaults = UserDefaults.standard jobTextField.text = userDefaults.value(forKey: "job") as? String

Which in case has no difference. It'd be great to know when I can't use one of them.

Thanks a lot :)

I've set some user defaults using let userDefaults = UserDefaults.standard, and when I'm retrieving them, I can use any of these:

jobTextField.text = userDefaults.object(forKey: "job") as? String

OR I can use

jobTextField.text = userDefaults.value(forKey: "job") as? String

in what case this will has a difference? It'd be great to know when I can NOT use one of them.

Thanks a lot :)

edited title
Link
rmaddy
  • 319.5k
  • 44
  • 548
  • 591

What is the different between object(defaultNameforKey:) and value(keyforKey:) in UserDefaults

Source Link
Ennabah
  • 2.6k
  • 2
  • 24
  • 40
Loading