Skip to content

Instantly share code, notes, and snippets.

View timelincoln7648's full-sized avatar

Kody timelincoln7648

View GitHub Profile
@timelincoln7648
timelincoln7648 / AppDelegate.swift
Last active January 17, 2020 22:31
function to add notification listeners to the Optimizely client
func addListeners() {
let notificationCenter = optimizely.notificationCenter
//notification fired when a value is returned by isFeatureEnabled function call
_ = notificationCenter?.addDecisionNotificationListener(decisionListener: { (type, userId, attributes, decisionInfo) in
print("Received decision notification: \(type) \(userId) \(String(describing: attributes)) \(decisionInfo)")
})
//notification fired when SDK polls for a new datafile and the datafile has changed
_ = notificationCenter?.addDatafileChangeNotificationListener(datafileListener: { (_) in
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] = [
@timelincoln7648
timelincoln7648 / ViewController.swift
Created January 17, 2020 21:36
linking optimizely isFeatureEnabled
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)")
@IBAction func showMessage(sender: UIButton) {
var enabled = false
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))
}
@IBAction func showMessage(sender: UIButton) {
let alertController = UIAlertController(title: "Alert", message: enabled ? "Hello World!" : "Nothing to see here...", preferredStyle: UIAlertController.Style.alert)
var enabled = false
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))
}
import UIKit
class ViewController: UIViewController {
let delegate = UIApplication.shared.delegate as! AppDelegate
@IBAction func showMessage(sender: UIButton) {
let userId = "user123"
let attributes: [String: Any] = [
"customerId": 123, // Attributes used for targeted audience-based rollout
@timelincoln7648
timelincoln7648 / ViewController.swift
Created January 10, 2020 22:16
linking optimizely isFeatureEnabled
let userId = "user123"
let attributes: [String: Any] = [
"customerId": 123, // Attributes used for targeted audience-based rollout
"isVip": true,
]
let enabled = delegate.optimizely.isFeatureEnabled(featureKey: "hello_world", userId: userId, attributes: attributes)
print("Feature is enabled? - \(enabled) for userId: \(userId)")
@timelincoln7648
timelincoln7648 / ViewController.swift
Created January 10, 2020 22:14
linking AppDelegate
let delegate = UIApplication.shared.delegate as! AppDelegate
@IBAction func showMessage(sender: UIButton) {
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)
@timelincoln7648
timelincoln7648 / customize_optimizely.swift
Created January 10, 2020 21:59
Customization options for the Optimizely Swift SDK
let customLogger = CustomLogger()
let logLevel = OptimizelyLogLevel.debug
let customDownloadIntervalInSecs = 30
let optimizely = OptimizelyClient(sdkKey: sdkKey,
logger: customLogger,
periodicDownloadInterval: customDownloadIntervalInSecs,
defaultLogLevel: logLevel)