- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我创建了 appGroups 并使用该组设置了 NSUserDefaults
。我有一个观察者,当值更改时不会触发该观察者。
let defaults = NSUserDefaults(suiteName: "group.daniesy.text")!
defaults.addObserver(self, forKeyPath: "temp", options: NSKeyValueObservingOptions.New, context: nil)
defaults.setBool(!defaults.boolForKey("temp"), forKey: "temp")
defaults.synchronize()
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
println("changed")
}
但是,如果我忽略 appGroup 并使用 NSUserDefaults.standardUserDefaults()
,它会按预期工作。知道为什么它不起作用吗?
最佳答案
Key-Value Observing and NSUserDefaults
In previous releases, KVO could only be used on the instance of NSUserDefaults returned by the +standardUserDefaults method. Additionally, changes from other processes (such as defaults(1), extensions, or other apps in an app group) were ignored by KVO. These limitations have both been corrected. Changes from other processes will be delivered asynchronously on the main queue, and ignore NSKeyValueObservingOptionPrior.
关于ios - 使用 suiteName 检测 NSUserDefaults 的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26599465/
我试图掌握某种单元测试,所以我们创建了模拟用户默认设置。 class MockUserDefaults: UserDefaults { var gameStyleChanged = 0 overrid
我创建了 appGroups 并使用该组设置了 NSUserDefaults。我有一个观察者,当值更改时不会触发该观察者。 let defaults = NSUserDefaults(suiteNam
在我的项目中,我使用应用程序组将数据传输到 Apple Watch!这看起来像这样 let sharedDefaults = NSUserDefaults(suiteName: "group.com.
有点被这个难住了。我正在开发一个需要通过 NSUserDefaults 与其容器应用程序通信的 Xcode 扩展。为此,您需要在扩展程序和容器应用程序中设置一个应用程序组授权,签署您的应用程序,然后像
我在使用 NSUserDefaults(suiteName: "group.app-ID") 时遇到问题。 我尝试将 NSArray 保存到 viewDidLoad() 中容器应用程序的 NSUser
我是一名优秀的程序员,十分优秀!