@@ -10,7 +10,17 @@ import Foundation
10
10
11
11
class Utils {
12
12
13
- static var sdkVersion : String ?
13
+ // - Bundle(for: OptimizelyManager.self) not working properly to get SDK bundle within unit tests
14
+ // - Bundle(identifier: bundleIdentifier) works ok consistently
15
+ // - CocoaPods uses its own bundle identifier, so let it use Bundle(for:) as a fallback
16
+ // CocoaPods copies "s.version" in podspec to "CFBundleShortVersionString" in its own Info.plist file
17
+ static var sdkVersion : String = {
18
+ let bundle = Bundle ( identifier: " com.optimizely.OptimizelySwiftSDK " ) ?? Bundle ( for: OptimizelyManager . self)
19
+ guard let version = bundle. infoDictionary![ " CFBundleShortVersionString " ] as? String else {
20
+ return " 3.0.0 "
21
+ }
22
+ return version
23
+ } ( )
14
24
15
25
// @objc NSNumber can be casted either Bool, Int, or Double
16
26
// more filtering required to avoid NSNumber(false, true) interpreted as Int(0, 1) instead of Bool
@@ -115,25 +125,4 @@ class Utils {
115
125
guard isBoolType ( value) else { return nil }
116
126
return ( value as! Bool )
117
127
}
118
-
119
- static func getSDKVersion( ) -> String {
120
-
121
- // - Bundle(for: OptimizelyManager.self) not working properly to get SDK bundle within unit tests
122
- // - Bundle(identifier: bundleIdentifier) works ok consistently
123
- // - CocoaPods uses its own bundle identifier, so let it use Bundle(for:) as a fallback
124
- // CocoaPods copies "s.version" in podspec to "CFBundleShortVersionString" in its own Info.plist file
125
- if let sdkVersion = sdkVersion {
126
- return sdkVersion
127
- }
128
-
129
- let bundle = Bundle ( identifier: " com.optimizely.OptimizelySwiftSDK " ) ?? Bundle ( for: OptimizelyManager . self)
130
- guard let version = bundle. infoDictionary![ " CFBundleShortVersionString " ] as? String else {
131
- fatalError ( " Check if SDK framework identifier is correct " )
132
- }
133
-
134
- sdkVersion = version
135
-
136
- return version
137
- }
138
-
139
128
}
0 commit comments