Skip to content

Commit 01d0898

Browse files
Added a builder block for project config. Improved how project config is initialized. Fixed code comments.
1 parent 846563c commit 01d0898

File tree

22 files changed

+290
-110
lines changed

22 files changed

+290
-110
lines changed

OptimizelySDKCore/OptimizelySDKCore.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
EA064BCA1DD3FC8800DF7537 /* OPTLYQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = EA064BC61DD3FC8800DF7537 /* OPTLYQueue.m */; };
2323
EA064BCE1DD3FCD700DF7537 /* OPTLYQueueTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA064BCB1DD3FC9F00DF7537 /* OPTLYQueueTest.m */; };
2424
EA064BCF1DD3FCD800DF7537 /* OPTLYQueueTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA064BCB1DD3FC9F00DF7537 /* OPTLYQueueTest.m */; };
25+
EA2C242D1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = EA2C242B1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h */; settings = {ATTRIBUTES = (Public, ); }; };
26+
EA2C242E1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = EA2C242B1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h */; settings = {ATTRIBUTES = (Public, ); }; };
27+
EA2C242F1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = EA2C242C1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m */; };
28+
EA2C24301DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = EA2C242C1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m */; };
2529
EA2FA8071DC5DBA000B1D81B /* OptimizelySDKCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA2FA7FE1DC5DBA000B1D81B /* OptimizelySDKCore.framework */; };
2630
EA2FA8271DC5DBB100B1D81B /* OptimizelySDKCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA2FA81E1DC5DBB100B1D81B /* OptimizelySDKCore.framework */; };
2731
EA2FA9771DC6F3CF00B1D81B /* murmur3.h in Headers */ = {isa = PBXBuildFile; fileRef = EA2FA9701DC6F3CF00B1D81B /* murmur3.h */; };
@@ -206,8 +210,8 @@
206210
EA5249651DC7B69A00AF6685 /* OPTLYEventDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = EA5249631DC7B69A00AF6685 /* OPTLYEventDispatcher.m */; };
207211
EA5249771DC7C6EF00AF6685 /* OPTLYEventDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = EA5249621DC7B69A00AF6685 /* OPTLYEventDispatcher.h */; settings = {ATTRIBUTES = (Public, ); }; };
208212
EA5249F21DC7FACF00AF6685 /* OPTLYEventDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = EA5249631DC7B69A00AF6685 /* OPTLYEventDispatcher.m */; };
209-
EA87A02A1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = EA87A0281DE31453002E9EF7 /* OPTLYUserProfile.h */; };
210-
EA87A02B1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = EA87A0281DE31453002E9EF7 /* OPTLYUserProfile.h */; };
213+
EA87A02A1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = EA87A0281DE31453002E9EF7 /* OPTLYUserProfile.h */; settings = {ATTRIBUTES = (Public, ); }; };
214+
EA87A02B1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = EA87A0281DE31453002E9EF7 /* OPTLYUserProfile.h */; settings = {ATTRIBUTES = (Public, ); }; };
211215
EA87A02C1DE31453002E9EF7 /* OPTLYUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = EA87A0291DE31453002E9EF7 /* OPTLYUserProfile.m */; };
212216
EA87A02D1DE31453002E9EF7 /* OPTLYUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = EA87A0291DE31453002E9EF7 /* OPTLYUserProfile.m */; };
213217
/* End PBXBuildFile section */
@@ -256,6 +260,8 @@
256260
EA064BC51DD3FC8800DF7537 /* OPTLYQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYQueue.h; sourceTree = "<group>"; };
257261
EA064BC61DD3FC8800DF7537 /* OPTLYQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYQueue.m; sourceTree = "<group>"; };
258262
EA064BCB1DD3FC9F00DF7537 /* OPTLYQueueTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYQueueTest.m; sourceTree = "<group>"; };
263+
EA2C242B1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYProjectConfigBuilder.h; sourceTree = "<group>"; };
264+
EA2C242C1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYProjectConfigBuilder.m; sourceTree = "<group>"; };
259265
EA2FA7FE1DC5DBA000B1D81B /* OptimizelySDKCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OptimizelySDKCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
260266
EA2FA8061DC5DBA000B1D81B /* OptimizelySDKCoreiOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OptimizelySDKCoreiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
261267
EA2FA81E1DC5DBB100B1D81B /* OptimizelySDKCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OptimizelySDKCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -537,6 +543,8 @@
537543
children = (
538544
EA2FAB1D1DC6F58800B1D81B /* OPTLYBuilder.h */,
539545
EA2FAB1E1DC6F58800B1D81B /* OPTLYBuilder.m */,
546+
EA2C242B1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h */,
547+
EA2C242C1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m */,
540548
);
541549
name = Builder;
542550
sourceTree = "<group>";
@@ -674,7 +682,6 @@
674682
EA2FAA4C1DC6F53E00B1D81B /* Optimizely.h in Headers */,
675683
EA2FAB001DC6F57200B1D81B /* OPTLYExperiment.h in Headers */,
676684
EA2FAB321DC6F59D00B1D81B /* OPTLYErrorHandler.h in Headers */,
677-
EA87A02A1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */,
678685
EA2FAB0C1DC6F57200B1D81B /* OPTLYProjectConfig.h in Headers */,
679686
EA2FAB281DC6F59100B1D81B /* OPTLYBucketer.h in Headers */,
680687
EA2FAB201DC6F58800B1D81B /* OPTLYBuilder.h in Headers */,
@@ -687,6 +694,8 @@
687694
EA2FAB381DC6F59D00B1D81B /* OPTLYErrorHandlerMessages.h in Headers */,
688695
EA5249641DC7B69A00AF6685 /* OPTLYEventDispatcher.h in Headers */,
689696
EA2FAB731DC6F5F400B1D81B /* OPTLYLog.h in Headers */,
697+
EA2C242D1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h in Headers */,
698+
EA87A02A1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */,
690699
EA064BC71DD3FC8800DF7537 /* OPTLYQueue.h in Headers */,
691700
EA2FAB791DC6F5F400B1D81B /* OPTLYMacros.h in Headers */,
692701
EA2FAAF41DC6F57200B1D81B /* OPTLYEventTicket.h in Headers */,
@@ -721,7 +730,6 @@
721730
EA2FAB011DC6F57200B1D81B /* OPTLYExperiment.h in Headers */,
722731
EA2FAB291DC6F59100B1D81B /* OPTLYBucketer.h in Headers */,
723732
EA2FAA4D1DC6F53E00B1D81B /* Optimizely.h in Headers */,
724-
EA87A02B1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */,
725733
EA2FAB0D1DC6F57200B1D81B /* OPTLYProjectConfig.h in Headers */,
726734
EA2FAB331DC6F59D00B1D81B /* OPTLYErrorHandler.h in Headers */,
727735
EA2FAB211DC6F58800B1D81B /* OPTLYBuilder.h in Headers */,
@@ -734,7 +742,9 @@
734742
EA2FAB391DC6F59D00B1D81B /* OPTLYErrorHandlerMessages.h in Headers */,
735743
EA5249771DC7C6EF00AF6685 /* OPTLYEventDispatcher.h in Headers */,
736744
EA2FAB741DC6F5F400B1D81B /* OPTLYLog.h in Headers */,
745+
EA87A02B1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */,
737746
EA064BC81DD3FC8800DF7537 /* OPTLYQueue.h in Headers */,
747+
EA2C242E1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h in Headers */,
738748
EA2FAC7B1DC70EBC00B1D81B /* murmur3.h in Headers */,
739749
EA2FAB7A1DC6F5F400B1D81B /* OPTLYMacros.h in Headers */,
740750
EA2FAA951DC6F57100B1D81B /* OPTLYBaseCondition.h in Headers */,
@@ -1112,6 +1122,7 @@
11121122
EA2FAC151DC6FFC600B1D81B /* OPTLYEventHeader.m in Sources */,
11131123
EA2FAC161DC6FFC600B1D81B /* OPTLYEventLayerState.m in Sources */,
11141124
EA5249651DC7B69A00AF6685 /* OPTLYEventDispatcher.m in Sources */,
1125+
EA2C242F1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m in Sources */,
11151126
EA2FAC171DC6FFC600B1D81B /* OPTLYEventMetric.m in Sources */,
11161127
EA2FAC181DC6FFC600B1D81B /* OPTLYEventParameterKeys.m in Sources */,
11171128
EA2FAC191DC6FFC600B1D81B /* OPTLYEventRelatedEvent.m in Sources */,
@@ -1178,6 +1189,7 @@
11781189
EA2FABF01DC6FFA100B1D81B /* OPTLYEventHeader.m in Sources */,
11791190
EA2FABF11DC6FFA100B1D81B /* OPTLYEventLayerState.m in Sources */,
11801191
EA5249F21DC7FACF00AF6685 /* OPTLYEventDispatcher.m in Sources */,
1192+
EA2C24301DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m in Sources */,
11811193
EA2FABF21DC6FFA100B1D81B /* OPTLYEventMetric.m in Sources */,
11821194
EA2FABF31DC6FFA100B1D81B /* OPTLYEventParameterKeys.m in Sources */,
11831195
EA2FABF41DC6FFA100B1D81B /* OPTLYEventRelatedEvent.m in Sources */,

OptimizelySDKCore/OptimizelySDKCore/OPTLYBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef void (^OPTLYBuilderBlock)(OPTLYBuilder * _Nullable builder);
4545
/// The logger is by default set to one that is created by Optimizely. This default logger can be overridden by any object that conforms to the OPTLYLogger protocol.
4646
@property (nonatomic, readwrite, strong, nullable) id<OPTLYLogger> logger;
4747
/// User profile stores user-specific data, like bucketing.
48-
@property (nonatomic, strong, nullable) id<OPTLYUserProfile> userProfile;
48+
@property (nonatomic, readwrite, strong, nullable) id<OPTLYUserProfile> userProfile;
4949

5050
/// Create an Optimizely Builder object.
5151
+ (nullable instancetype)builderWithBlock:(nonnull OPTLYBuilderBlock)block;

OptimizelySDKCore/OptimizelySDKCore/OPTLYBuilder.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "OPTLYEventDispatcher.h"
2222
#import "OPTLYLogger.h"
2323
#import "OPTLYProjectConfig.h"
24+
#import "OPTLYUserProfile.h"
2425

2526
@implementation OPTLYBuilder
2627

@@ -47,10 +48,13 @@ - (id)initWithBlock:(OPTLYBuilderBlock)block {
4748
if (_datafile == nil) {
4849
return nil;
4950
}
50-
_config = [[OPTLYProjectConfig alloc] initWithDatafile:_datafile
51-
withLogger:_logger
52-
withErrorHandler:_errorHandler
53-
withUserProfile:_userProfile];
51+
52+
_config = [OPTLYProjectConfig initWithBuilderBlock:^(OPTLYProjectConfigBuilder * _Nullable builder) {
53+
builder.datafile = _datafile;
54+
builder.userProfile = _userProfile;
55+
builder.logger = _logger;
56+
builder.errorHandler = _errorHandler;
57+
}];
5458

5559
if (_config == nil) {
5660
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
@@ -102,4 +106,12 @@ - (NSData *)datafile {
102106
return _logger;
103107
}
104108

109+
- (id<OPTLYUserProfile>)userProfile {
110+
if (!_userProfile) {
111+
_userProfile = [[OPTLYUserProfileNoOp alloc] init];
112+
}
113+
return _userProfile;
114+
}
115+
116+
105117
@end

OptimizelySDKCore/OptimizelySDKCore/OPTLYErrorHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,9 @@
5454
@interface OPTLYErrorHandlerDefault : NSObject <OPTLYErrorHandler>
5555
@end
5656

57+
/**
58+
* OPTLYErrorHandlerNoOp comforms to the OPTLYErrorHandler protocol,
59+
* but all methods perform a no op.
60+
*/
5761
@interface OPTLYErrorHandlerNoOp : NSObject <OPTLYErrorHandler>
5862
@end

OptimizelySDKCore/OptimizelySDKCore/OPTLYEventDispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
/**
5858
* OPTLYEventDispatcherNoOp comforms to the OPTLYEventDispatcher protocol,
59-
* but all methods performa a no op.
59+
* but all methods perform a no op.
6060
*/
6161
@interface OPTLYEventDispatcherNoOp : NSObject<OPTLYEventDispatcher>
6262
@end

OptimizelySDKCore/OptimizelySDKCore/OPTLYProjectConfig.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#import <Foundation/Foundation.h>
1818
#import <JSONModel/JSONModelLib.h>
19+
#import "OPTLYProjectConfigBuilder.h"
1920

2021
@class OPTLYAttribute, OPTLYAudience, OPTLYBucketer, OPTLYEvent, OPTLYExperiment, OPTLYGroup, OPTLYVariation, OPTLYVariable;
2122
@protocol OPTLYAttribute, OPTLYAudience, OPTLYBucketer, OPTLYErrorHandler, OPTLYEvent, OPTLYExperiment, OPTLYGroup, OPTLYLogger, OPTLYUserProfile, OPTLYVariable, OPTLYVariation;
@@ -57,13 +58,15 @@
5758
@property (nonatomic, strong, nullable) id<OPTLYUserProfile, Ignore> userProfile;
5859

5960
/**
60-
* Initialize the Project Config from the Data File.
61+
* Initialize the Project Config from a builder block.
6162
*/
62-
// TODO - make initializer with builder block
63-
- (nullable instancetype)initWithDatafile:(nullable NSData *)datafile
64-
withLogger:(nullable id<OPTLYLogger>)logger
65-
withErrorHandler:(nullable id<OPTLYErrorHandler>)errorHandler
66-
withUserProfile:(nullable id<OPTLYUserProfile>)userProfile;
63+
+ (nullable instancetype)initWithBuilderBlock:(nonnull OPTLYProjectConfigBuilderBlock)block;
64+
65+
/**
66+
* Initialize the Project Config from a datafile.
67+
*/
68+
- (nullable instancetype)initWithDatafile:(nonnull NSData *)datafile;
69+
6770
/**
6871
* Get an Experiment object for a key.
6972
*/

OptimizelySDKCore/OptimizelySDKCore/OPTLYProjectConfig.m

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#import "OPTLYVariable.h"
3131
#import "OPTLYUserProfile.h"
3232
#import "OPTLYVariable.h"
33-
#import "OPTLYUserProfile.h"
3433

3534
NSString * const kClientEngine = @"objective-c-sdk-core";
3635

@@ -50,14 +49,44 @@ @interface OPTLYProjectConfig()
5049

5150
@implementation OPTLYProjectConfig
5251

53-
- (nullable instancetype)initWithDatafile:(nullable NSData *)datafile
54-
withLogger:(nullable id<OPTLYLogger>)logger
55-
withErrorHandler:(nullable id<OPTLYErrorHandler>)errorHandler
56-
withUserProfile:(nullable id<OPTLYUserProfile>)userProfile
57-
{
58-
if (errorHandler) {
59-
if ([OPTLYErrorHandler conformsToOPTLYErrorHandlerProtocol:[errorHandler class]]) {
60-
_errorHandler = (id<OPTLYErrorHandler, Ignore>)errorHandler;
52+
+ (nullable instancetype)initWithBuilderBlock:(nonnull OPTLYProjectConfigBuilderBlock)block {
53+
return [[self alloc] initWithBuilder:[OPTLYProjectConfigBuilder builderWithBlock:block]];
54+
}
55+
56+
- (instancetype)initWithBuilder:(OPTLYProjectConfigBuilder *)builder {
57+
58+
if (!builder.datafile) {
59+
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
60+
code:OPTLYErrorTypesDatafileInvalid
61+
userInfo:@{NSLocalizedDescriptionKey :
62+
NSLocalizedString(OPTLYErrorHandlerMessagesDataFileInvalid, nil)}];
63+
[_errorHandler handleError:error];
64+
65+
NSString *logMessage = OPTLYErrorHandlerMessagesDataFileInvalid;
66+
[_logger logMessage:logMessage withLevel:OptimizelyLogLevelError];
67+
return nil;
68+
}
69+
70+
NSError *datafileError;
71+
@try {
72+
self = [super initWithData:builder.datafile error:&datafileError];
73+
}
74+
@catch (NSException *datafileException) {
75+
[_errorHandler handleException:datafileException];
76+
}
77+
78+
if (datafileError)
79+
{
80+
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
81+
code:OPTLYErrorTypesDatafileInvalid
82+
userInfo:datafileError.userInfo];
83+
[_errorHandler handleError:error];
84+
return nil;
85+
}
86+
87+
if (builder.errorHandler) {
88+
if ([OPTLYErrorHandler conformsToOPTLYErrorHandlerProtocol:[builder.errorHandler class]]) {
89+
_errorHandler = (id<OPTLYErrorHandler, Ignore>)builder.errorHandler;
6190
} else {
6291
_errorHandler = [OPTLYErrorHandlerDefault new];
6392
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
@@ -71,10 +100,11 @@ - (nullable instancetype)initWithDatafile:(nullable NSData *)datafile
71100
}
72101
}
73102

74-
if (logger) {
75-
if ([logger conformsToProtocol:@protocol(OPTLYLogger)]) {
76-
_logger = (id<OPTLYLogger, Ignore>)logger;
103+
if (builder.logger) {
104+
if ([builder.logger conformsToProtocol:@protocol(OPTLYLogger)]) {
105+
_logger = (id<OPTLYLogger, Ignore>)builder.logger;
77106
} else {
107+
_logger = [OPTLYLoggerDefault new];
78108
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
79109
code:OPTLYErrorTypesLoggerInvalid
80110
userInfo:@{NSLocalizedDescriptionKey :
@@ -86,9 +116,9 @@ - (nullable instancetype)initWithDatafile:(nullable NSData *)datafile
86116
}
87117
}
88118

89-
if (userProfile) {
90-
if ([OPTLYUserProfile conformsToOPTLYUserProfileProtocol:[userProfile class]]) {
91-
_userProfile = (id<OPTLYUserProfile, Ignore>)userProfile;
119+
if (builder.userProfile) {
120+
if ([OPTLYUserProfileUtility conformsToOPTLYUserProfileProtocol:[builder.userProfile class]]) {
121+
_userProfile = (id<OPTLYUserProfile, Ignore>)builder.userProfile;
92122
} else {
93123
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
94124
code:OPTLYErrorTypesUserProfile
@@ -100,36 +130,13 @@ - (nullable instancetype)initWithDatafile:(nullable NSData *)datafile
100130
[_logger logMessage:logMessage withLevel:OptimizelyLogLevelError];
101131
}
102132
}
103-
104-
OPTLYProjectConfig* projectConfig = nil;
105-
NSError *datafileError;
106-
@try {
107-
if (!datafile) {
108-
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
109-
code:OPTLYErrorTypesDatafileInvalid
110-
userInfo:@{NSLocalizedDescriptionKey :
111-
NSLocalizedString(OPTLYErrorHandlerMessagesDataFileInvalid, nil)}];
112-
[_errorHandler handleError:error];
113-
114-
NSString *logMessage = OPTLYErrorHandlerMessagesDataFileInvalid;
115-
[_logger logMessage:logMessage withLevel:OptimizelyLogLevelError];
116-
} else {
117-
projectConfig = [[OPTLYProjectConfig alloc] initWithData:datafile error:&datafileError];
118-
}
119-
}
120-
@catch (NSException *datafileException) {
121-
[_errorHandler handleException:datafileException];
122-
}
123-
124-
if (datafileError)
125-
{
126-
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
127-
code:OPTLYErrorTypesDatafileInvalid
128-
userInfo:datafileError.userInfo];
129-
[_errorHandler handleError:error];
130-
}
131-
132-
return projectConfig;
133+
return self;
134+
}
135+
136+
- (nullable instancetype)initWithDatafile:(nonnull NSData *)datafile {
137+
return [OPTLYProjectConfig initWithBuilderBlock:^(OPTLYProjectConfigBuilder * _Nullable builder) {
138+
builder.datafile = datafile;
139+
}];
133140
}
134141

135142
#pragma mark -- Getters --
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/****************************************************************************
2+
* Copyright 2016, Optimizely, Inc. and contributors *
3+
* *
4+
* Licensed under the Apache License, Version 2.0 (the "License"); *
5+
* you may not use this file except in compliance with the License. *
6+
* You may obtain a copy of the License at *
7+
* *
8+
* http://www.apache.org/licenses/LICENSE-2.0 *
9+
* *
10+
* Unless required by applicable law or agreed to in writing, software *
11+
* distributed under the License is distributed on an "AS IS" BASIS, *
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13+
* See the License for the specific language governing permissions and *
14+
* limitations under the License. *
15+
***************************************************************************/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
/**
20+
* This class contains details related to how the Optimizely Project Config instance is built.
21+
*/
22+
23+
@class OPTLYProjectConfigBuilder;
24+
@protocol OPTLYErrorHandler, OPTLYLogger, OPTLYUserProfile;
25+
26+
/// This is a block that takes the builder values.
27+
typedef void (^OPTLYProjectConfigBuilderBlock)(OPTLYProjectConfigBuilder * _Nullable builder);
28+
29+
@interface OPTLYProjectConfigBuilder : NSObject
30+
31+
/**
32+
* Initializer for Optimizely Project Config Builder object
33+
*
34+
* @param block The builder block with which to initialize the Optimizely Project Config Builder object
35+
* @return An instance of OPTLYProjectConfigBuilder
36+
*/
37+
+ (nullable instancetype)builderWithBlock:(nonnull OPTLYProjectConfigBuilderBlock)block;
38+
39+
/// optional error handler
40+
@property (nonatomic, strong, nullable) id<OPTLYErrorHandler> errorHandler;
41+
/// optional logger
42+
@property (nonatomic, strong, nullable) id<OPTLYLogger> logger;
43+
/// optional user profile
44+
@property (nonatomic, strong, nullable) id<OPTLYUserProfile> userProfile;
45+
/// the non optional datafile contents
46+
@property (nonatomic, strong, nonnull) NSData *datafile;
47+
48+
@end

0 commit comments

Comments
 (0)