No results for ""
EXPAND ALL
  • Home
  • API docs

iOS SDK 5.x to 6.0 migration guide for Objective-C

Read time: 3 minutes
Last edited: Feb 09, 2023

Overview

This topic explains how to adapt Objective-C code that currently uses a 5.x version of the iOS client-side SDK to use version 6.0 or later. The sections in this topic address different changes and updates between versions 5.x and 6.0 of the SDK.

The Objective-C bridging types for the iOS SDK are implemented in Swift, where names are prefixed by Objc. This document refers to the types by the names exposed to Objective-C.

Understanding the new LDValue type

The 6.0 release of the iOS client-side SDK introduces a new type that represents a value of any valid JSON type: LDValue. To learn more, read the generated documentation. You can initialize the LDValue type with different types of values to support arbitrary JSON data.

Here is an example:

LDValue *nullValue = [LDValue ofNull];
LDValue *boolValue = [LDValue ofBool:YES];
LDValue *numericValue = [LDValue ofNumber:@5.5];
LDValue *stringValue = [LDValue ofString:@"beta_testers"];
LDValue *complexValue = [LDValue ofDict:@{@"groups": [LDValue ofArray:@[[LDValue ofBool:YES]]]}];

Understanding the changes to creating users

The LDUser.custom property has changed in type from NSDictionary<NSString*, id> * _Nullable to NSDictionary<NSString*, LDValue*> * _Nonnull.

Here is an example of the change:

LDUser *user = [[LDUser alloc] initWithKey:@"user-key-123abc"];
user.custom = @{@"group": @"beta"};

The isEqual function on LDUser has changed. It no longer only compares the key property, and now compares all properties of the instance.

LDUser *user1 = [[LDUser alloc] initWithKey:@"user-key-123abc"];
user1.name = @"Jane Smith";
LDUser *user2 = [[LDUser alloc] initWithKey:@"user-key-123abc"];
user2.name = @"John Smith";
// Results in true
[user1 isEqual:user2]

Setting "custom" as a private attribute no longer sets all custom attributes as private. The SDK considers only the custom attribute with the key "custom" as private.

Changes to variation functions

The LDClient functions arrayVariation and dictionaryVariation have been removed. The new jsonVariation function lets you evaluate flags with any value type.

NSArray *result = [[LDClient get] arrayVariationForKey:@"flag-key-123abc" defaultValue:@[]];

Understanding changes to variationDetail functions

The LDClient functions arrayVariationDetail and dictionaryVariationDetail have been removed. The new jsonVariationDetail function allows evaluating flags with any resultant value type. The LDJSONEvaluationDetail type is used to store the resultant variation and detailed evaluation information.

The reason property of the detailed evaluation result types has also changed from NSDictionary<NSString*, id> * _Nullable to NSDictionary<NSString*, LDValue*> * _Nullable.

LDArrayEvaluationDetail *result = [[LDClient get] arrayVariationDetailForKey:@"flag-key-123abc" defaultValue:@[]];
NSArray* resultValue = result.value;
NSDictionary<NSString*, id> *reason = result.reason;

Understanding the changes to flag value observers

The LDClient previously provided per-type functions for registering observers for flag values. These have been replaced with a single observe function you can use with flag variations of any JSON type.

[[LDClient get] observeBool:@"flag-key-123abc" owner:self handler:^(LDBoolChangedFlag * _Nonnull changedFlag) {
Bool newValue = changedFlag.newValue;
}];

Recording custom events

If your application uses track to record custom events, you must remove the error parameter. The track functions no longer have the potential to error from invalid custom event data, because the data parameter is now restricted to the LDValue type. Change provided data types to LDValue instances.

Here is an example of the required changes:

NSError* err = nil;
NSDictionary* data = @{@"abc": @123};
[[LDClient get] trackWithKey:@"key" data:data error:&err];
if (err != nil) {
// Do something with the error
}