Rollout Using Swift SDK

Rollout enables you to release new features gradually and reduce risk. Instead of pushing updates to all users at once, you can use a feature flag to expose a new feature to a small segment, measure business impact, and then scale up safely. If anything goes wrong, do an instant rollback — no redeploy required.

This capability is powered by the Choose API using the Rollout selector. The call returns a variation that includes the following rolloutFlag conditions for each user:

  • rolloutFlag = true → user is included the rollout test and should see the new feature
  • rolloutFlag = false → user is in the rollout test but is assigned to the control group (feature off)
  • no flag returned → user isn’t included in the rollout campaign
🚧

Best practice

Put Rollout campaigns in a selector group, fetch all flag statuses at session start, and cache them for the session if they don’t change. Don’t mix campaign types in the same Choose call.

📘

For more information:

Code example

import DyLibrary 

func fetchRolloutFlags() async { 
    let result = await DYSdk.shared().choose.chooseVariations( 
        selectorNames: ["example-campaign-1", "example-campaign-2"], 
        page: Page.homePage(pageLocation: "Page Location", referrer: "otherScreenName"), 
        selectorGroups: ["feature_flags"], // optional, if configured for your section 
        selectorPreviews: [], 
        dayPart: .dinner, 
        cart: [ 
            CartItem(productId: "example-id", quantity: 1, itemPrice: 5, 
                innerProducts: [CartInnerItem(productId: "example-id", quantity: 1, itemPrice: 3)]) 
        ], 

        branchId: "example-branch-id", 
        options: ChooseOptions(), 
        pageAttributes: ["Attr1": PageAttribute("value-1"), "Attr2": PageAttribute(5)], 
        recsProductData: RecsProductDataOptions(), 
        listedItems: ["example-list-item"] 
    ) 

    switch result.status { 
    case .success, .warning: 
        if let choices = result.choices { 
            for choice in choices { 
                if let variation = choice.variations.first as? CustomVariation { 
                    let rolloutFlag = variation.rolloutFlag ?? false 
                    let customJsonPayload = variation.payload 
                    print("selector=\(choice.name) rolloutFlag=\(rolloutFlag ? "true" : "false")") 
                    print("payloadData: \(customJsonPayload.data)") 
                } 
            } 
        } 
        result.warnings?.forEach { print($0) } 

    case .error: 
        if let error = result.error { print(error) } 
    } 
}