File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
FirebaseRemoteConfig/SwiftNew Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ public class UserDefaultsManager: NSObject {
7373 }
7474 }
7575
76+ private static let sharedInstanceMapLock = NSLock ( )
7677 private static var sharedInstanceMap : [ String : UserDefaults ] = [ : ]
7778
7879 /// Returns the shared user defaults instance for the given bundle identifier.
@@ -81,14 +82,14 @@ public class UserDefaultsManager: NSObject {
8182 /// - Returns: The shared user defaults instance.
8283 @objc ( sharedUserDefaultsForBundleIdentifier: )
8384 static func sharedUserDefaultsForBundleIdentifier( _ bundleIdentifier: String ) -> UserDefaults {
84- objc_sync_enter ( sharedInstanceMap)
85- defer { objc_sync_exit ( sharedInstanceMap) }
86- if let instance = sharedInstanceMap [ bundleIdentifier] {
87- return instance
85+ sharedInstanceMapLock. withLock {
86+ if let instance = sharedInstanceMap [ bundleIdentifier] {
87+ return instance
88+ }
89+ let userDefaults = UserDefaults ( suiteName: userDefaultsSuiteName ( for: bundleIdentifier) ) !
90+ sharedInstanceMap [ bundleIdentifier] = userDefaults
91+ return userDefaults
8892 }
89- let userDefaults = UserDefaults ( suiteName: userDefaultsSuiteName ( for: bundleIdentifier) ) !
90- sharedInstanceMap [ bundleIdentifier] = userDefaults
91- return userDefaults
9293 }
9394
9495 /// Returns the user defaults suite name for the given bundle identifier.
You can’t perform that action at this time.
0 commit comments