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

iOS SDK 5.x to 6.0 migration guide for Swift

Read time: 4 minutes
Last edited: Jan 04, 2024

Overview

This topic explains how to adapt Swift code that currently uses a 5.x version of the iOS client-side SDK to use version 6.0 or later.

Sections in this topic address different changes and updates between versions 5.x and 6.0 of the SDK.

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 about the new type, read the generated documentation. The LDValue enum implements several ExpressibleBy protocols allowing constants to be created the same as other Swift types, as shown below.

Understanding the changes to configuration

The LDConfig class only requires changes if the application specifies the privateUserAttributes property. The type of the property has changed from [String] to [UserAttribute].

Here is an example that highlights the changes:

Setting "custom" as a private attribute no longer sets all custom attributes private. Only the custom attribute with the key "custom" would be considered private by the SDK.

Understanding the changes to creating users

Similarly to LDConfig.privateUserAttributes, LDUser.privateAttributes has been updated to use UserAttribute. Additionally LDUser.custom now user the LDValue type rather than Any for specifying the value of custom attributes.

Here is an example that highlights the changes:

The Equatable instance for LDUser has also changed. It now compares all properties, rather than only the key property.

Changes to variation functions

The iOS SDK now provides functions per-type for retrieving the variation for a given flag. To retrieve variation values that are complex (JSON arrays or objects), use the new jsonVariation function.

Here is an example:

Changes to variationDetail functions

The iOS SDK now provides function per-type for retrieving the detailed variation result for a given flag. To retrieve variation values that are complex, such as JSON arrays or objects, use the new jsonVariation function. The reason information associated with a LDEvaluationDetail has also changed from [String: Any]? to [String: LDValue]?.

Here is an example:

Recording custom events

If your application uses track to record custom events, remove try statements. This function no longer throws an error. Additionally, the data parameter type has changed from Any? to LDValue?. If your application provides the data parameter, you may need to update it to provide an LDValue type.

Here is an example: