Skip to content

Instantly share code, notes, and snippets.

@timelincoln7648
Created January 17, 2020 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelincoln7648/ee53bce58399da75ecae84314b03b6b7 to your computer and use it in GitHub Desktop.
Save timelincoln7648/ee53bce58399da75ecae84314b03b6b7 to your computer and use it in GitHub Desktop.
complete code
import UIKit
class ViewController: UIViewController {
let delegate = UIApplication.shared.delegate as! AppDelegate
@IBAction func showMessage(sender: UIButton) {
var enabled = false
let userId = "user123"
let attributes: [String: Any] = [
"customerId": 123, // Attributes used for targeted audience-based rollout
"isVip": true,
]
enabled = delegate.optimizely.isFeatureEnabled(featureKey: "hello_world", userId: userId, attributes: attributes)
print("Feature is enabled? - \(enabled) for userId: \(userId)")
let alertController = UIAlertController(title: "Alert", message: enabled ? "Hello World!" : "Nothing to see here...", preferredStyle: UIAlertController.Style.alert)
if enabled {
alertController.addAction(UIAlertAction(title: "Hello!", style: UIAlertAction.Style.default, handler: nil))
} else {
alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: nil))
}
present(alertController, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment