Is NSUserDefault thread safe?

前端 未结 2 1892
忘掉有多难
忘掉有多难 2021-01-31 15:40

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html says it is

...shou

相关标签:
2条回答
  • 2021-01-31 16:29

    Speaking for 10.10 and iOS8 if you looking into the implementation you'll find that -[NSUserDefaults setObject:forKey:] is calling __CFPreferencesSetAppValueWithContainer, which will eventually end up in +[CFPrefsSource withSourceForIdentifier:user:byHost:container:perform:]. This method is using a pthread_mutex_t to lock the access to the dictionary containing the values.

    So NSUserDefaults is thread safe.

    0 讨论(0)
  • 2021-01-31 16:36

    The Apple iOS 5.1 and OS X 10.7 documentation say that it is thread-safe; therefore it is thread-safe.

    0 讨论(0)
提交回复
热议问题