Skip to content

Commit b6d3119

Browse files
thomaszurkan-optimizelyjaeopt
authored andcommitted
(fix): make all changes for using id instead of NSObject * (#382)
* make all changes for using id instead of NSObject * * added unit tests
1 parent b284650 commit b6d3119

25 files changed

+240
-140
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ To learn more about Feature Management, read our [knowledge base article introdu
173173
- (NSNumber *)getFeatureVariableDouble:(nullable NSString *)featureKey
174174
variableKey:(nullable NSString *)variableKey
175175
userId:(nullable NSString *)userId
176-
attributes:(nullable NSDictionary<NSString *, NSString *> *)attributes;
176+
attributes:(nullable NSDictionary<NSString *, id> *)attributes;
177177
- (NSNumber *)getFeatureVariableInteger:(nullable NSString *)featureKey
178178
variableKey:(nullable NSString *)variableKey
179179
userId:(nullable NSString *)userId

OptimizelyDemoApp/AppDelegate.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
125125

126126
})
127127
#endif
128-
let variation = optimizelyClient?.activate((self?.experimentKey)!, userId: (self?.userId)!)
128+
let attributes = ["browser_number": 7]
129+
let variation = optimizelyClient?.activate((self?.experimentKey)!, userId: (self?.userId)!, attributes: attributes)
130+
129131

130132
if let experiments = optimizelyClient?.optimizely?.config?.experiments {
131133
for experiment in experiments {

OptimizelySDKCore/OptimizelySDKCore/OPTLYAudience.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ - (void)setConditionsWithNSDictionary:(NSDictionary *)dictionary {
6464
}
6565
}
6666

67-
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
67+
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
6868
NSObject<OPTLYCondition> *condition = (NSObject<OPTLYCondition> *)[self.conditions firstObject];
6969
if (condition) {
7070
// Log Audience Evaluation Started

OptimizelySDKCore/OptimizelySDKCore/OPTLYAudienceBaseCondition.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ + (BOOL) isBaseConditionJSON:(nonnull NSData *)jsonData {
2626
return [jsonData isKindOfClass:[NSString class]];
2727
}
2828

29-
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
29+
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
3030
if (attributes == nil) {
3131
// if the user did not pass in attributes, return false
3232
return [NSNumber numberWithBool:false];

OptimizelySDKCore/OptimizelySDKCore/OPTLYBaseCondition.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ + (BOOL)isBaseConditionJSON:(nonnull NSData *)jsonData {
5252
return [jsonData isKindOfClass:[NSDictionary class]];
5353
}
5454

55-
- (nullable NSNumber *)evaluateMatchTypeExact:(NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
55+
- (nullable NSNumber *)evaluateMatchTypeExact:(NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
5656
// check if user attributes contain a value that is of similar class type to our value and also equals to our value, else return Null
5757

5858
// check if condition value is invalid
@@ -100,12 +100,12 @@ - (nullable NSNumber *)evaluateMatchTypeExact:(NSDictionary<NSString *, NSObject
100100
return NULL;
101101
}
102102

103-
- (nullable NSNumber *)evaluateMatchTypeExist:(NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
103+
- (nullable NSNumber *)evaluateMatchTypeExist:(NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
104104
// check if user attributes contain our name as a key to a Non nullable object
105105
return [NSNumber numberWithBool:([attributes objectForKey:self.name] && ![attributes[self.name] isKindOfClass:[NSNull class]])];
106106
}
107107

108-
- (nullable NSNumber *)evaluateMatchTypeSubstring:(NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
108+
- (nullable NSNumber *)evaluateMatchTypeSubstring:(NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
109109
// check if user attributes contain our value as substring
110110

111111
// check if condition value is invalid
@@ -140,7 +140,7 @@ - (nullable NSNumber *)evaluateMatchTypeSubstring:(NSDictionary<NSString *, NSOb
140140
return [NSNumber numberWithBool:containsSubstring];
141141
}
142142

143-
- (nullable NSNumber *)evaluateMatchTypeGreaterThan:(NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
143+
- (nullable NSNumber *)evaluateMatchTypeGreaterThan:(NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
144144
// check if user attributes contain a value greater than our value
145145

146146
// check if condition value is invalid
@@ -181,7 +181,7 @@ - (nullable NSNumber *)evaluateMatchTypeGreaterThan:(NSDictionary<NSString *, NS
181181
return [NSNumber numberWithBool: ([userValue doubleValue] > [ourValue doubleValue])];
182182
}
183183

184-
- (nullable NSNumber *)evaluateMatchTypeLessThan:(NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
184+
- (nullable NSNumber *)evaluateMatchTypeLessThan:(NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
185185
// check if user attributes contain a value lesser than our value
186186

187187
// check if condition value is invalid
@@ -222,7 +222,7 @@ - (nullable NSNumber *)evaluateMatchTypeLessThan:(NSDictionary<NSString *, NSObj
222222
return [NSNumber numberWithBool: ([userValue doubleValue] < [ourValue doubleValue])];
223223
}
224224

225-
- (nullable NSNumber *)evaluateCustomMatchType:(NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
225+
- (nullable NSNumber *)evaluateCustomMatchType:(NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
226226

227227
if (![self.type isEqual:OPTLYDatafileKeysCustomAttributeConditionType]){
228228
//Check if given type is the required type
@@ -268,7 +268,7 @@ - (nullable NSNumber *)evaluateCustomMatchType:(NSDictionary<NSString *, NSObjec
268268
/**
269269
* Evaluates the condition against the user attributes, returns NULL if invalid.
270270
*/
271-
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
271+
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
272272
// check user attribute value for the condition and match type against our condition value
273273
return [self evaluateCustomMatchType: attributes projectConfig:config];
274274
}

OptimizelySDKCore/OptimizelySDKCore/OPTLYCondition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* Evaluate the condition against the user attributes.
2424
*/
25-
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config;
25+
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config;
2626

2727
@end
2828

OptimizelySDKCore/OptimizelySDKCore/OPTLYCondition.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ @implementation OPTLYCondition
183183

184184
@implementation OPTLYAndCondition
185185

186-
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
186+
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
187187
// According to the matrix:
188188
// false and true is false
189189
// false and null is false
@@ -218,7 +218,7 @@ - (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<N
218218

219219
@implementation OPTLYOrCondition
220220

221-
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
221+
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
222222
// According to the matrix:
223223
// true returns true
224224
// false or null is null
@@ -250,7 +250,7 @@ - (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<N
250250

251251
@implementation OPTLYNotCondition
252252

253-
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
253+
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
254254
// return the negative of the subcondition
255255
NSNumber * result = [NSNumber new];
256256
result = [self.subCondition evaluateConditionsWithAttributes:attributes projectConfig:config];

OptimizelySDKCore/OptimizelySDKCore/OPTLYDecisionService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
*/
5555
- (nullable OPTLYVariation *)getVariation:(nonnull NSString *)userId
5656
experiment:(nonnull OPTLYExperiment *)experiment
57-
attributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes;
57+
attributes:(nullable NSDictionary<NSString *, id> *)attributes;
5858

5959
/**
6060
* Get a variation the user is bucketed into for the given FeatureFlag
@@ -65,6 +65,6 @@
6565
*/
6666
- (nullable OPTLYFeatureDecision *)getVariationForFeature:(nonnull OPTLYFeatureFlag *)featureFlag
6767
userId:(nonnull NSString *)userId
68-
attributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes;
68+
attributes:(nullable NSDictionary<NSString *, id> *)attributes;
6969

7070
@end

OptimizelySDKCore/OptimizelySDKCore/OPTLYDecisionService.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ - (instancetype) initWithProjectConfig:(OPTLYProjectConfig *)config
5353

5454
- (OPTLYVariation *)getVariation:(NSString *)userId
5555
experiment:(OPTLYExperiment *)experiment
56-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes
56+
attributes:(NSDictionary<NSString *, id> *)attributes
5757
{
5858
NSDictionary *userProfileDict = nil;
5959
OPTLYVariation *bucketedVariation = nil;
@@ -126,7 +126,7 @@ - (OPTLYVariation *)getVariation:(NSString *)userId
126126

127127
- (OPTLYFeatureDecision *)getVariationForFeature:(OPTLYFeatureFlag *)featureFlag
128128
userId:(NSString *)userId
129-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
129+
attributes:(NSDictionary<NSString *, id> *)attributes {
130130

131131
//Evaluate in this order:
132132

@@ -158,7 +158,7 @@ - (OPTLYFeatureDecision *)getVariationForFeature:(OPTLYFeatureFlag *)featureFlag
158158
# pragma mark - Helper Methods
159159

160160
- (NSString *)getBucketingId:(NSString *)userId
161-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
161+
attributes:(NSDictionary<NSString *, id> *)attributes {
162162

163163
// By default, the bucketing ID should be the user ID .
164164
NSString *bucketingId = userId;
@@ -194,7 +194,7 @@ - (OPTLYExperiment *)getExperimentInGroup:(OPTLYGroup *)group bucketingId:(NSStr
194194
- (OPTLYFeatureDecision *)getVariationForFeatureGroup:(OPTLYFeatureFlag *)featureFlag
195195
groupId:(NSString *)groupId
196196
userId:(NSString *)userId
197-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
197+
attributes:(NSDictionary<NSString *, id> *)attributes {
198198

199199
OPTLYFeatureDecision *decision = nil;
200200
NSString *logMessage = nil;
@@ -230,7 +230,7 @@ - (OPTLYFeatureDecision *)getVariationForFeatureGroup:(OPTLYFeatureFlag *)featur
230230

231231
- (OPTLYFeatureDecision *)getVariationForFeatureExperiment:(OPTLYFeatureFlag *)featureFlag
232232
userId:(NSString *)userId
233-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
233+
attributes:(NSDictionary<NSString *, id> *)attributes {
234234

235235
NSString *featureFlagKey = featureFlag.key;
236236
NSArray *experimentIds = featureFlag.experimentIds;
@@ -266,7 +266,7 @@ - (OPTLYFeatureDecision *)getVariationForFeatureExperiment:(OPTLYFeatureFlag *)f
266266

267267
- (OPTLYFeatureDecision *)getVariationForFeatureRollout:(OPTLYFeatureFlag *)featureFlag
268268
userId:(NSString *)userId
269-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
269+
attributes:(NSDictionary<NSString *, id> *)attributes {
270270

271271
NSString *bucketing_id = [self getBucketingId:userId attributes:attributes];
272272
NSString *featureFlagKey = featureFlag.key;
@@ -451,15 +451,15 @@ - (NSString *)getVariationIdFromUserProfile:(NSDictionary *)userProfileDict
451451

452452
- (nullable NSNumber *)evaluateAudienceWithId:(NSString *)audienceId
453453
config:(OPTLYProjectConfig *)config
454-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes
454+
attributes:(NSDictionary<NSString *, id> *)attributes
455455
{
456456
OPTLYAudience *audience = [config getAudienceForId:audienceId];
457457
return [audience evaluateConditionsWithAttributes:attributes projectConfig:config];
458458
}
459459

460460
- (BOOL)evaluateAudienceIdsForExperiment:(OPTLYExperiment *)experiment
461461
config:(OPTLYProjectConfig *)config
462-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes
462+
attributes:(NSDictionary<NSString *, id> *)attributes
463463
{
464464
NSArray *audienceIds = experiment.audienceIds;
465465
// if there are no audiences, ALL users should be part of the experiment
@@ -478,7 +478,7 @@ - (BOOL)evaluateAudienceIdsForExperiment:(OPTLYExperiment *)experiment
478478

479479
- (BOOL)evaluateAudienceConditionsForExperiment:(OPTLYExperiment *)experiment
480480
config:(OPTLYProjectConfig *)config
481-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes
481+
attributes:(NSDictionary<NSString *, id> *)attributes
482482
{
483483
if (experiment.audienceConditions.count == 0) {
484484
return true;
@@ -505,7 +505,7 @@ - (BOOL)shouldEvaluateUsingAudienceConditions:(OPTLYExperiment *)experiment
505505
}
506506

507507
// Returns empty dictionary if attributes nil
508-
- (NSDictionary<NSString *, NSObject *> *)validateAttributes:(NSDictionary<NSString *, NSObject *> *)attributes
508+
- (NSDictionary<NSString *, id> *)validateAttributes:(NSDictionary<NSString *, id> *)attributes
509509
{
510510
// if there are audiences, but no user attributes, Defaults to empty attributes
511511
if (attributes == nil) {
@@ -516,7 +516,7 @@ - (BOOL)shouldEvaluateUsingAudienceConditions:(OPTLYExperiment *)experiment
516516

517517
- (BOOL)isUserInExperiment:(OPTLYProjectConfig *)config
518518
experiment:(OPTLYExperiment *)experiment
519-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes
519+
attributes:(NSDictionary<NSString *, id> *)attributes
520520
{
521521
attributes = [self validateAttributes:attributes];
522522

@@ -531,7 +531,7 @@ - (BOOL)isUserInExperiment:(OPTLYProjectConfig *)config
531531
- (BOOL)userPassesTargeting:(OPTLYProjectConfig *)config
532532
experiment:(OPTLYExperiment *)experiment
533533
userId:(NSString *)userId
534-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes
534+
attributes:(NSDictionary<NSString *, id> *)attributes
535535
{
536536
// check if the user is in the experiment
537537
BOOL isUserInExperiment = [self isUserInExperiment:config experiment:experiment attributes:attributes];

OptimizelySDKCore/OptimizelySDKCore/OPTLYEventBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_END
4343
- (nullable NSDictionary *)buildImpressionEventForUser:(nonnull NSString *)userId
4444
experiment:(nonnull OPTLYExperiment *)experiment
4545
variation:(nonnull OPTLYVariation *)variation
46-
attributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes;
46+
attributes:(nullable NSDictionary<NSString *, id> *)attributes;
4747

4848
/**
4949
* Create the parameters for a conversion event.
@@ -58,7 +58,7 @@ NS_ASSUME_NONNULL_END
5858
- (nullable NSDictionary *)buildConversionEventForUser:(nonnull NSString *)userId
5959
event:(nonnull OPTLYEvent *)event
6060
eventTags:(nullable NSDictionary *)eventTags
61-
attributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes;
61+
attributes:(nullable NSDictionary<NSString *, id> *)attributes;
6262
@end
6363

6464
@interface OPTLYEventBuilderDefault : NSObject<OPTLYEventBuilder>

OptimizelySDKCore/OptimizelySDKCore/OPTLYEventBuilder.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ - (instancetype)initWithConfig:(OPTLYProjectConfig *)config {
5656
- (NSDictionary *)buildImpressionEventForUser:(NSString *)userId
5757
experiment:(OPTLYExperiment *)experiment
5858
variation:(OPTLYVariation *)variation
59-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
59+
attributes:(NSDictionary<NSString *, id> *)attributes {
6060
if (!self.config) {
6161
return nil;
6262
}
@@ -71,7 +71,7 @@ - (NSDictionary *)buildImpressionEventForUser:(NSString *)userId
7171
- (NSDictionary *)buildConversionEventForUser:(NSString *)userId
7272
event:(OPTLYEvent *)event
7373
eventTags:(NSDictionary *)eventTags
74-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
74+
attributes:(NSDictionary<NSString *, id> *)attributes {
7575

7676
if (!self.config) {
7777
return nil;
@@ -87,7 +87,7 @@ - (NSDictionary *)buildConversionEventForUser:(NSString *)userId
8787
}
8888

8989
- (NSDictionary *)createCommonParamsForUser:(NSString *)userId
90-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
90+
attributes:(NSDictionary<NSString *, id> *)attributes {
9191
NSMutableDictionary *commonParams = [NSMutableDictionary new];
9292

9393
NSMutableDictionary *visitor = [NSMutableDictionary new];
@@ -199,7 +199,7 @@ - (NSDictionary *)filterEventTags:(NSDictionary *)eventTags {
199199
}
200200

201201
- (NSArray *)createUserFeatures:(OPTLYProjectConfig *)config
202-
attributes:(NSDictionary<NSString *, NSObject *> *)attributes {
202+
attributes:(NSDictionary<NSString *, id> *)attributes {
203203

204204
NSNumber *botFiltering = config.botFiltering;
205205
NSMutableArray *features = [NSMutableArray new];

OptimizelySDKCore/OptimizelySDKCore/OPTLYExperiment.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ - (void)setAudienceConditionsWithNSArray:(NSArray *)array {
6262
}
6363
}
6464

65-
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
65+
- (nullable NSNumber *)evaluateConditionsWithAttributes:(nullable NSDictionary<NSString *, id> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
6666

6767
NSObject<OPTLYCondition> *condition = (NSObject<OPTLYCondition> *)[self.audienceConditions firstObject];
6868
if (condition) {

0 commit comments

Comments
 (0)