NSUserDefaults register方法作用

 /**
     -registerDefaults: adds the registrationDictionary to the last item in every search list. This means that after NSUserDefaults has looked for a value in every other valid location, it will look in registered defaults, making them useful as a "fallback" value. Registered defaults are never stored between runs of an application, and are visible only to the application that registers them.
     
     Default values from Defaults Configuration Files will automatically be registered.
     */
    open func register(defaults registrationDictionary: [String : Any])

NSUserDefault有个注册的方法,该方法的使用有几点需要注意。

第一:该方法需要提前注册,要不然取得值都是nil。

第二:该方法是不保存本地的。app重启后数据就会删除。

第三:该数据的存储方式优先级很低。如果你在本地plist中已经有对应的key值了,会优先使用已有的key值,而不会使用你注册的值。

第四:如果你使用UserDefaults.standard方式注册,就要使用UserDefaults.standard方式取值。其他方式同理。

posted @ 2019-12-30 14:09  何以解幽  阅读(294)  评论(0编辑  收藏  举报