Skip to content

Commit 6604759

Browse files
Add missing nullable and nonnull annotations. Only log attribute not found if it is not found (#311)
* only log attribute not found if it is not found * update nullable and nonnull * add proper nullable and nonnull annotations * fix nullable annotation * fix nullable warning * cleanup test * update demo to work with swift 4.2 * mixpanel does not work with 4.2 * update travis to use xcode 9.4
1 parent 12bf48a commit 6604759

File tree

14 files changed

+73
-84
lines changed

14 files changed

+73
-84
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: objective-c
2-
osx_image: xcode8.3
2+
osx_image: xcode9.4
33
branches:
44
only:
55
- master

OptimizelyDemoApp/AppDelegate.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4444
let datafileManagerDownloadInterval = 20000
4545

4646

47-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
47+
func applicationDidFinishLaunching(_ application: UIApplication) {
4848

4949
// ********************************************************
5050
// ***************** Integration Samples ******************
@@ -57,7 +57,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5757
// ** Google Analytics is initialized via the GoogleService-info.plist file
5858
Amplitude.instance().initializeApiKey("YOUR_API_KEY_HERE")
5959
Mixpanel.initialize(token:"MIXPANEL_TOKEN")
60-
Localytics.autoIntegrate("YOUR-LOCALYTICS-APP-KEY", launchOptions: launchOptions)
60+
Localytics.autoIntegrate("YOUR-LOCALYTICS-APP-KEY", launchOptions: nil)
6161

6262
#endif
6363
// **************************************************
@@ -151,8 +151,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
151151
// let optimizelyClient = optimizelyManager?.initialize()
152152
// let variation = optimizelyClient?.activate(self.experimentKey, userId:self.userId, attributes: self.attributes)
153153
// self.setRootViewController(optimizelyClient: optimizelyClient, bucketedVariation:variation)
154-
155-
return true;
156154
}
157155

158156
func setRootViewController(optimizelyClient: OPTLYClient!, bucketedVariation:OPTLYVariation?) {

OptimizelySDKCore/OptimizelySDKCore/OPTLYProjectConfig.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@ - (nullable NSString *)getAttributeIdForKey:(nonnull NSString *)attributeKey {
196196
} else if (hasReservedPrefix) {
197197
attributeId = attributeKey;
198198
}
199-
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesAttributeNotFound, attributeKey];
200-
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelError];
199+
200+
if (attributeId == nil) {
201+
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesAttributeNotFound, attributeKey];
202+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelError];
203+
}
201204
return attributeId;
202205
}
203206

OptimizelySDKCore/OptimizelySDKCore/Optimizely.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ typedef NS_ENUM(NSInteger, OPTLYLiveVariableError) {
110110
* @param userId The user ID to be used for bucketing.
111111
* @return forced variation if it exists, otherwise return nil.
112112
*/
113-
- (OPTLYVariation *_Nullable)getForcedVariation:(nonnull NSString *)experimentKey
113+
- (nullable OPTLYVariation *)getForcedVariation:(nonnull NSString *)experimentKey
114114
userId:(nonnull NSString *)userId;
115115

116116
/**
@@ -145,7 +145,7 @@ typedef NS_ENUM(NSInteger, OPTLYLiveVariableError) {
145145
* @param attributes The user's attributes.
146146
* @return BOOL feature variable value.
147147
*/
148-
- (NSNumber *)getFeatureVariableBoolean:(nullable NSString *)featureKey
148+
- (nullable NSNumber *)getFeatureVariableBoolean:(nullable NSString *)featureKey
149149
variableKey:(nullable NSString *)variableKey
150150
userId:(nullable NSString *)userId
151151
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
@@ -158,7 +158,7 @@ typedef NS_ENUM(NSInteger, OPTLYLiveVariableError) {
158158
* @param attributes The user's attributes.
159159
* @return double feature variable value of type double.
160160
*/
161-
- (NSNumber *)getFeatureVariableDouble:(nullable NSString *)featureKey
161+
- (nullable NSNumber *)getFeatureVariableDouble:(nullable NSString *)featureKey
162162
variableKey:(nullable NSString *)variableKey
163163
userId:(nullable NSString *)userId
164164
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
@@ -171,7 +171,7 @@ typedef NS_ENUM(NSInteger, OPTLYLiveVariableError) {
171171
* @param attributes The user's attributes.
172172
* @return int feature variable value of type integer.
173173
*/
174-
- (NSNumber *)getFeatureVariableInteger:(nullable NSString *)featureKey
174+
- (nullable NSNumber *)getFeatureVariableInteger:(nullable NSString *)featureKey
175175
variableKey:(nullable NSString *)variableKey
176176
userId:(nullable NSString *)userId
177177
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
@@ -184,7 +184,7 @@ typedef NS_ENUM(NSInteger, OPTLYLiveVariableError) {
184184
* @param attributes The user's attributes.
185185
* @return NSString feature variable value of type string.
186186
*/
187-
- (NSString *_Nullable)getFeatureVariableString:(nullable NSString *)featureKey
187+
- (nullable NSString *)getFeatureVariableString:(nullable NSString *)featureKey
188188
variableKey:(nullable NSString *)variableKey
189189
userId:(nullable NSString *)userId
190190
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
* @param builderBlock The builder block containing the datafile fetch interval.
4545
* @return an Optimizely Datafile Manager instance.
4646
*/
47-
+ (nullable instancetype)init:(nonnull OPTLYDatafileManagerBuilderBlock)builderBlock
47+
+ (nullable instancetype)init:(nullable OPTLYDatafileManagerBuilderBlock)builderBlock
4848
__attribute((deprecated("Use OPTLYDatafileManagerDefault initWithBuilder method instead.")));
4949

5050
/**
5151
* Init with OPTLYDatafileManagerBuilder object
5252
* @param builder The OPTLYDatafileManagerBuilder object containing the datafile fetch interval.
5353
* @return an Optimizely Datafile Manager instance.
5454
*/
55-
- (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder;
55+
- (nullable instancetype)initWithBuilder:(nullable OPTLYDatafileManagerBuilder *)builder;
5656

5757
@end

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ @interface OPTLYDatafileManagerDefault ()
4141

4242
@implementation OPTLYDatafileManagerDefault
4343

44-
+ (nullable instancetype)init:(nonnull OPTLYDatafileManagerBuilderBlock)builderBlock {
44+
+ (nullable instancetype)init:(OPTLYDatafileManagerBuilderBlock)builderBlock {
4545
return [[self alloc] initWithBuilder:[OPTLYDatafileManagerBuilder builderWithBlock:builderBlock]];
4646
}
4747

48-
- (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
48+
- (nullable instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
4949
if (builder != nil) {
5050
self = [super init];
5151
if (self != nil) {

OptimizelySDKDatafileManager/OptimizelySDKDatafileManagerTests/OPTLYDatafileManagerSwiftTest.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ class OPTLYDatafileManagerSwiftTest: XCTestCase {
3333
func testOPTLYDatafileManagerInitWithBuilder() -> Void {
3434
let datafileConfig = OPTLYDatafileConfig.init(projectId: self.kProjectId, withSDKKey: nil)
3535
XCTAssertNotNil(datafileConfig, "data file config should not be nil.")
36-
self.datafileManager = OPTLYDatafileManagerDefault.init(builder: OPTLYDatafileManagerBuilder.init(block: { (builder) in
36+
self.datafileManager = OPTLYDatafileManagerDefault.init(builder: OPTLYDatafileManagerBuilder(block: { (builder) in
3737
builder?.datafileConfig = datafileConfig!
3838
}))
39+
3940
XCTAssertNotNil(self.datafileManager, "data file manager should not be nil.")
4041
}
4142
}

OptimizelySDKShared/OptimizelySDKShared/OPTLYClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ __attribute((deprecated("Use OPTLYClient initWithBuilder method instead.")));
4343
* @param builder The OPTLYClientBuilder object which has datafile, event handler, event dispatcher, and other configurations to be set.
4444
* @return OPTLYClient instance
4545
*/
46-
- (instancetype)initWithBuilder:(OPTLYClientBuilder *)builder;
46+
- (nonnull instancetype)initWithBuilder:(nullable OPTLYClientBuilder *)builder;
4747

4848
- (OPTLYNotificationCenter *_Nullable)notificationCenter;
4949

OptimizelySDKShared/OptimizelySDKShared/OPTLYClient.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ + (nonnull instancetype)init:(OPTLYClientBuilderBlock)builderBlock {
3636
return [[self alloc] initWithBuilder:[OPTLYClientBuilder builderWithBlock:builderBlock]];
3737
}
3838

39-
- (instancetype)init {
39+
- (nonnull instancetype)init {
4040
return [self initWithBuilder:nil];
4141
}
4242

43-
- (instancetype)initWithBuilder:(OPTLYClientBuilder *)builder {
43+
- (nonnull instancetype)initWithBuilder:(nullable OPTLYClientBuilder *)builder {
4444
self = [super init];
4545
if (self) {
4646
if (builder != nil) {
@@ -53,17 +53,17 @@ - (instancetype)initWithBuilder:(OPTLYClientBuilder *)builder {
5353
return self;
5454
}
5555

56-
-(OPTLYNotificationCenter *)notificationCenter {
56+
-(nullable OPTLYNotificationCenter *)notificationCenter {
5757
return self.optimizely.notificationCenter;
5858
}
5959

6060
#pragma mark activate methods
61-
- (OPTLYVariation *)activate:(nonnull NSString *)experimentKey
61+
- (nullable OPTLYVariation *)activate:(nonnull NSString *)experimentKey
6262
userId:(nonnull NSString *)userId {
6363
return [self activate:experimentKey userId:userId attributes:nil];
6464
}
6565

66-
- (OPTLYVariation *)activate:(NSString *)experimentKey
66+
- (nullable OPTLYVariation *)activate:(NSString *)experimentKey
6767
userId:(NSString *)userId
6868
attributes:(NSDictionary<NSString *,NSString *> *)attributes {
6969
if (self.optimizely == nil) {
@@ -79,14 +79,14 @@ - (OPTLYVariation *)activate:(NSString *)experimentKey
7979
}
8080

8181
#pragma mark getVariation methods
82-
- (OPTLYVariation *)variation:(NSString *)experimentKey
82+
- (nullable OPTLYVariation *)variation:(NSString *)experimentKey
8383
userId:(NSString *)userId {
8484
return [self variation:experimentKey
8585
userId:userId
8686
attributes:nil];
8787
}
8888

89-
- (OPTLYVariation *)variation:(NSString *)experimentKey
89+
- (nullable OPTLYVariation *)variation:(NSString *)experimentKey
9090
userId:(NSString *)userId
9191
attributes:(NSDictionary<NSString *,NSString *> *)attributes {
9292
if (self.optimizely == nil) {
@@ -103,7 +103,7 @@ - (OPTLYVariation *)variation:(NSString *)experimentKey
103103

104104
#pragma mark Forced Variation Methods
105105

106-
- (OPTLYVariation *)getForcedVariation:(nonnull NSString *)experimentKey
106+
- (nullable OPTLYVariation *)getForcedVariation:(nonnull NSString *)experimentKey
107107
userId:(nonnull NSString *)userId {
108108
if (self.optimizely == nil) {
109109
[self.logger logMessage:OPTLYLoggerMessagesClientDummyOptimizelyError

OptimizelySDKShared/OptimizelySDKShared/OPTLYDatafileConfig.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
***************************************************************************/
1616
#import <Foundation/Foundation.h>
1717

18-
extern NSString * const DEFAULT_HOST;
19-
extern NSString * const OPTLY_PROJECTID_SUFFIX;
20-
extern NSString * const OPTLY_ENVIRONMENTS_SUFFIX;
18+
extern NSString * __nonnull const DEFAULT_HOST;
19+
extern NSString * __nonnull const OPTLY_PROJECTID_SUFFIX;
20+
extern NSString * __nonnull const OPTLY_ENVIRONMENTS_SUFFIX;
2121

2222
@interface OPTLYDatafileConfig : NSObject
23-
- (nullable id)initWithProjectId:(NSString *)projectId withSDKKey:(NSString *)sdkKey withHost:(NSString *)host;
24-
- (nullable id)initWithProjectId:(NSString *)projectId withSDKKey:(NSString *)sdkKey;
25-
- (NSURL *) URLForKey;
26-
- (NSString *) key;
23+
- (nullable id)initWithProjectId:(nullable NSString *)projectId withSDKKey:(nullable NSString *)sdkKey withHost:(nonnull NSString *)host;
24+
- (nullable id)initWithProjectId:(nullable NSString *)projectId withSDKKey:(nullable NSString *)sdkKey;
25+
- (nonnull NSURL *) URLForKey;
26+
- (nonnull NSString *) key;
2727
@end
2828

2929
@interface OPTLYDatafileConfig(OPTLYHelpers)
30-
+ (NSString *)defaultProjectIdCdnPath:(NSString *)projectId;
31-
+ (NSString *)defaultSdkKeyCdnPath:(NSString *)sdkKey;
30+
+ (nonnull NSString *)defaultProjectIdCdnPath:(nonnull NSString *)projectId;
31+
+ (nonnull NSString *)defaultSdkKeyCdnPath:(nonnull NSString *)sdkKey;
3232
/*
3333
* Test if string s can be an Optimizely SDK key string.
3434
*/
35-
+ (BOOL)isValidKeyString:(NSString*)s;
35+
+ (BOOL)isValidKeyString:(nullable NSString*)s;
3636

3737
@end

OptimizelySDKShared/OptimizelySDKShared/OPTLYManagerBasic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ __attribute((deprecated("Use OPTLYManagerBasic initWithBuilder method instead.")
3131
* @param builder The OPTLYManagerBuilder object which has datafile manager, event dispatcher, and other configurations to be set.
3232
* @return OptimizelyManager instance
3333
*/
34-
- (instancetype)initWithBuilder:(OPTLYManagerBuilder *)builder;
34+
- (nullable instancetype)initWithBuilder:(nullable OPTLYManagerBuilder *)builder;
3535
@end

OptimizelySDKShared/OptimizelySDKShared/OPTLYManagerBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef void (^OPTLYManagerBuilderBlock)(OPTLYManagerBuilder * _Nullable builder
4343
@property (nonatomic, readwrite, strong, nullable) id<OPTLYUserProfileService> userProfileService;
4444

4545
/// init is disabled. Please use builderWithBlock to create a Manager Builder
46-
- (instancetype)init NS_UNAVAILABLE;
46+
- (nonnull instancetype)init NS_UNAVAILABLE;
4747
/// Create the Optimizely Manager Builder object.
4848
+ (nullable instancetype)builderWithBlock:(nonnull OPTLYManagerBuilderBlock)block;
4949

OptimizelySDKUserProfileService/OptimizelySDKUserProfileService/OPTLYUserProfileService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ __attribute((deprecated("Use OPTLYManager initWithBuilder method instead.")));
5959
* @param validExperimentIds An array of valid experiment ids. If default user profile contains
6060
* experiments not in this list, they are removed from user profile service.
6161
**/
62-
- (void)removeInvalidExperimentsForAllUsers:(NSArray<NSString *> *)validExperimentIds;
62+
- (void)removeInvalidExperimentsForAllUsers:(NSArray<NSString *> *_Nullable)validExperimentIds;
6363
@end

0 commit comments

Comments
 (0)