File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -74,18 +74,21 @@ import Foundation
74
74
open class DefaultUserProfileService : OPTUserProfileService {
75
75
public typealias UserProfileData = [ String : UPProfile ]
76
76
77
- var profiles : UserProfileData
77
+ var profiles : UserProfileData ?
78
78
let lock = DispatchQueue ( label: " com.optimizely.UserProfileService " )
79
79
let kStorageName = " user-profile-service "
80
80
81
81
public required init ( ) {
82
- profiles = UserDefaults . standard. dictionary ( forKey: kStorageName) as? UserProfileData ?? UserProfileData ( )
82
+ lock. async {
83
+ self . profiles = UserDefaults . standard. dictionary ( forKey: self . kStorageName) as? UserProfileData ?? UserProfileData ( )
84
+
85
+ }
83
86
}
84
87
85
88
open func lookup( userId: String ) -> UPProfile ? {
86
89
var retVal : UPProfile ?
87
90
lock. sync {
88
- retVal = profiles [ userId]
91
+ retVal = profiles ? [ userId]
89
92
}
90
93
return retVal
91
94
}
@@ -94,7 +97,7 @@ open class DefaultUserProfileService: OPTUserProfileService {
94
97
guard let userId = userProfile [ UserProfileKeys . kUserId] as? String else { return }
95
98
96
99
lock. async {
97
- self . profiles [ userId] = userProfile
100
+ self . profiles ? [ userId] = userProfile
98
101
let defaults = UserDefaults . standard
99
102
defaults. set ( self . profiles, forKey: self . kStorageName)
100
103
defaults. synchronize ( )
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import Foundation
10
10
11
11
class Utils {
12
12
13
+ static var sdkVersion : String ?
14
+
13
15
// @objc NSNumber can be casted either Bool, Int, or Double
14
16
// more filtering required to avoid NSNumber(false, true) interpreted as Int(0, 1) instead of Bool
15
17
@@ -120,11 +122,16 @@ class Utils {
120
122
// - Bundle(identifier: bundleIdentifier) works ok consistently
121
123
// - CocoaPods uses its own bundle identifier, so let it use Bundle(for:) as a fallback
122
124
// CocoaPods copies "s.version" in podspec to "CFBundleShortVersionString" in its own Info.plist file
125
+ if let sdkVersion = sdkVersion {
126
+ return sdkVersion
127
+ }
123
128
124
129
let bundle = Bundle ( identifier: " com.optimizely.OptimizelySwiftSDK " ) ?? Bundle ( for: OptimizelyManager . self)
125
130
guard let version = bundle. infoDictionary![ " CFBundleShortVersionString " ] as? String else {
126
131
fatalError ( " Check if SDK framework identifier is correct " )
127
132
}
133
+
134
+ sdkVersion = version
128
135
129
136
return version
130
137
}
You can’t perform that action at this time.
0 commit comments