App Features

App features let you control application behaviour remotely without releasing a new build. The SDK downloads feature data from the server, caches it locally, and notifies your code whenever the values change.

Accessing the features object

Use the features property on your MagifyClient instance:

let features = magify.features

features conforms to the Features protocol, which exposes typed accessors and an update callback.

Reading typed values

Every accessor returns an optional — it is nil when the key does not exist or the stored value cannot be converted to the requested type.

Boolean

if let isEnabled = magify.features.bool(forKey: "dark_mode_enabled") {
    // use isEnabled
}

String

if let title = magify.features.string(forKey: "onboarding_title") {
    label.text = title
}

Integer

if let retryCount = magify.features.int(forKey: "max_retry_count") {
    // use retryCount
}

Double

if let discount = magify.features.double(forKey: "discount_rate") {
    // use discount
}

Dictionary

Returns [String: Any?]? — suitable for loosely-typed composite values:

if let config = magify.features.dictionary(forKey: "paywall_config") {
    let variant = config["variant"] as? String
}

Raw value

value(forKey:) returns Any? without type conversion:

let raw = magify.features.value(forKey: "experiment_payload")

Custom decodable object

Use customObject(_:forKey:) to decode a JSON-serialised feature into any Decodable type. The method throws if decoding fails.

struct PaywallConfig: Decodable {
    let variant: String
    let price: Double
}

do {
    if let config = try magify.features.customObject(PaywallConfig.self, forKey: "paywall_config") {
        // use config.variant, config.price
    }
} catch {
    print("Failed to decode feature: \(error)")
}

Reacting to feature updates

Assign a closure to onUpdate to be notified whenever the SDK receives fresh feature values from the server.

magify.features.onUpdate = {
    // Re-read the values you care about
    let isEnabled = magify.features.bool(forKey: "dark_mode_enabled") ?? false
    self.applyDarkMode(isEnabled)
}

Remove the observer by setting onUpdate to nil.

Next step

For server-driven content items, see the Content section.

Related articles

Releases

Adjust

Analytics

CreativeBackground

BundleCreative

ConfigScope