From 6658c46c93fe86921505e4167fd5e291b7f5a787 Mon Sep 17 00:00:00 2001 From: Andre Terron Date: Tue, 10 Dec 2024 16:45:39 -0800 Subject: [PATCH 1/3] Update Swift docs for the initialize function --- docs/client/iOS/_initialize.mdx | 10 +++++----- docs/client/iOS/_options.mdx | 4 ++-- docs/client/iOS/_stableID.mdx | 2 +- docs/client/iOS/_statsigListening.mdx | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/client/iOS/_initialize.mdx b/docs/client/iOS/_initialize.mdx index 41c45b363..6e5fd3ffe 100644 --- a/docs/client/iOS/_initialize.mdx +++ b/docs/client/iOS/_initialize.mdx @@ -11,16 +11,16 @@ import TabItem from "@theme/TabItem"; ```swift -Statsig.start( +Statsig.initialize( sdkKey: "my_client_sdk_key", user: StatsigUser(userID: "my_user_id"), options: StatsigOptions(environment: StatsigEnvironment(tier: .Staging))) -{ errorMessage in +{ error in // Statsig has finished fetching the latest feature gate and experiment values for your user. // If you need the most recent values, you can get them now. - // You can also check errorMessage for any debugging information. + // You can also check error.message and error.code for any debugging information. } ``` @@ -30,11 +30,11 @@ Statsig.start( ```swift StatsigUser *user = [[StatsigUser alloc] initWithUserID:@"my_user_id"]; -[Statsig startWithSDKKey:@"my_client_sdk_key", user:user, completion:^(NSString * errorMessage) { +[Statsig initializeWithSDKKey:@"my_client_sdk_key", user:user, completion:^(StatsigClientError * error) { // Statsig has finished fetching the latest feature gate and experiment values for your user. // If you need the most recent values, you can get them now. - // You can also check errorMessage for any debugging information. + // You can also check error.message and error.code for any debugging information. }]; ``` diff --git a/docs/client/iOS/_options.mdx b/docs/client/iOS/_options.mdx index 7d183dece..1bab41959 100644 --- a/docs/client/iOS/_options.mdx +++ b/docs/client/iOS/_options.mdx @@ -1,4 +1,4 @@ -`Statsig.start()` takes an optional parameter `options` in addition to `sdkKey` and `user` that you can provide to customize the Statsig client. Here are the current options and we are always adding more to the list: +`Statsig.initialize()` takes an optional parameter `options` in addition to `sdkKey` and `user` that you can provide to customize the Statsig client. Here are the current options and we are always adding more to the list: - **initTimeout**: Double, default `3.0` - used to decide how long the Statsig client waits for the initial network request to respond before calling the completion block. The Statsig client will return either cached values (if any) or default values if checkGate/getConfig/getExperiment is called before the initial network request completes. @@ -45,7 +45,7 @@ } let opts = StatsigOptions(evaluationCallback: callback) - Statsig.start(sdkKey: "client-key", options: opts) + Statsig.initialize(sdkKey: "client-key", options: opts) ``` - **storageProvider**: StorageProvider, default `nil` diff --git a/docs/client/iOS/_stableID.mdx b/docs/client/iOS/_stableID.mdx index d17cf4237..d4fa07b00 100644 --- a/docs/client/iOS/_stableID.mdx +++ b/docs/client/iOS/_stableID.mdx @@ -10,7 +10,7 @@ export const GetStableID = () => ( export const OverrideStableID = () => ( {`let opts = StatsigOptions(overrideStableID: "my_stable_id") -Statsig.start(sdkKey: "client-xyx", options: opts) +Statsig.initialize(sdkKey: "client-xyx", options: opts) `} ); diff --git a/docs/client/iOS/_statsigListening.mdx b/docs/client/iOS/_statsigListening.mdx index fe035d271..41a7dbb09 100644 --- a/docs/client/iOS/_statsigListening.mdx +++ b/docs/client/iOS/_statsigListening.mdx @@ -8,14 +8,14 @@ export const AddedInVersion = "1.14.0"; In version v{AddedInVersion}+, you can now listen for changes in Statsig values. -This can be useful if you have one location that calls Statsig.start or Statsig.updateUser +This can be useful if you have one location that calls Statsig.initialize or Statsig.updateUser and you would like these changes to flow to separate locations. To use this API, simply have the class you wish to respond to these changes implement the `StatsigListening` protocol and add it as a listener. The StatsigListening protocol has two methods that can be implemented: -`onInitialized` - Will be called when the initialize request is returned in Statsig.start(). +`onInitialized` - Will be called when the initialize request is returned in Statsig.initialize(). An error string may be passed to this function if something went wrong with the network request. `onUserUpdated` - Will be called when the network request for Statsig.updateUser is returned. From 69682efa8830f879195089c06eacb13f490de553 Mon Sep 17 00:00:00 2001 From: Andre Terron Date: Mon, 6 Jan 2025 13:31:52 -0800 Subject: [PATCH 2/3] Update StatsigListening methods --- docs/client/iOS/_statsigListening.mdx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/client/iOS/_statsigListening.mdx b/docs/client/iOS/_statsigListening.mdx index 41a7dbb09..8c3a312b8 100644 --- a/docs/client/iOS/_statsigListening.mdx +++ b/docs/client/iOS/_statsigListening.mdx @@ -15,11 +15,11 @@ To use this API, simply have the class you wish to respond to these changes impl The StatsigListening protocol has two methods that can be implemented: -`onInitialized` - Will be called when the initialize request is returned in Statsig.initialize(). -An error string may be passed to this function if something went wrong with the network request. +`onInitializedWithResult` - Will be called when the initialize request is returned in Statsig.initialize(). +An error object may be passed to this function if something went wrong with the network request. -`onUserUpdated` - Will be called when the network request for Statsig.updateUser is returned. -An error string may be passed to this function if something went wrong with the network request. +`onUserUpdatedWithResult` - Will be called when the network request for Statsig.updateUser is returned. +An error object may be passed to this function if something went wrong with the network request. You may also check the new `Statsig.isInitialized()` to verify if Statsig has already completed initialization. @@ -50,17 +50,17 @@ class MyViewController: UIViewController, StatsigListening { private func renderLoading() { /* Some Loading UI */ } - private func renderError(error: String) { /* Some Error UI */ } + private func renderError(error: StatsigClientError) { /* Some Error UI */ } // StatsigListening Implementation - func onInitialized(_ error: String?) { + func onInitializedWithResult(_ error: StatsigClientError?) { if (error) { renderError(error) } render() } - func onUserUpdated(_ error: String?) { /* Optional rerender when User changed */ } + func onUserUpdatedWithResult(_ error: StatsigClientError?) { /* Optional rerender when User changed */ } } ``` From 23629fc6863e5323e6517f786b70a3fa32789055 Mon Sep 17 00:00:00 2001 From: Andre Terron Date: Wed, 8 Jan 2025 11:17:38 -0800 Subject: [PATCH 3/3] Make sure sample code works --- docs/client/iOS/_statsigListening.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/client/iOS/_statsigListening.mdx b/docs/client/iOS/_statsigListening.mdx index 8c3a312b8..2443ff192 100644 --- a/docs/client/iOS/_statsigListening.mdx +++ b/docs/client/iOS/_statsigListening.mdx @@ -40,7 +40,7 @@ class MyViewController: UIViewController, StatsigListening { } private func render() { - var showNewUI = Statsig.checkGate("new_ui_enabled", false) + var showNewUI = Statsig.checkGate("new_ui_enabled") if showNewUI { // Render the new } else { @@ -55,8 +55,9 @@ class MyViewController: UIViewController, StatsigListening { // StatsigListening Implementation func onInitializedWithResult(_ error: StatsigClientError?) { - if (error) { + if let error = error { renderError(error) + return } render() }