Detect changes on NSUserDefaults

后端 未结 5 2073
你的背包
你的背包 2020-12-29 23:45

I\'m developing an iOS application with latest SDK.

I want to know when a property on NSUserDefaults changes it value.

I have found this, but it

5条回答
  •  隐瞒了意图╮
    2020-12-30 00:34

    In Xcode help, the overview of UserDefaults class (the swifty name for NSUserDefaults) clearly states:

    You can use key-value observing to register observers for specific keys of interest in order to be notified of all updates to a local defaults database. For more details, see Key-Value Observing Programming Guide."

    I'll see if I can come up with a quick code-sample, but stack-overflow must be full of KVO samples in swift.

提交回复
热议问题