0

I want to observe defaults for that particulate key whenever I set a new value to that particular key then I want to perform a certain operation where I am observing the change.

//Global Variable 

var defaults =  UserDefaults()

//Set the value

self.defaults = UserDefaults(suiteName: "group.random.mugish")!
defaults.set("tempValueSet", forKey: "group.random.mugish")

//Read the value


let defaults2 = UserDefaults(suiteName: "group.random.mugish")
let x = defaults2?.string(forKey: "group.random.mugish")
Mohammad Mugish
  • 335
  • 1
  • 3
  • 13
  • KVO is not supported in swift. Try this: https://stackoverflow.com/questions/24175626/adding-observer-for-kvo-without-pointers-using-swift/32701309#32701309 – Lirik Jun 11 '19 at 15:08
  • @Lirik I believe, The answers to the question you have introduced are no longer working. – Iman Nia Jun 13 '19 at 07:29

0 Answers0