Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Swift docs for the initialize function #2404

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/client/iOS/_initialize.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import TabItem from "@theme/TabItem";
<TabItem value="swift">

```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.

}
```
Expand All @@ -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.
}];
```

Expand Down
4 changes: 2 additions & 2 deletions docs/client/iOS/_options.mdx
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion docs/client/iOS/_stableID.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const GetStableID = () => (
export const OverrideStableID = () => (
<CodeBlock language="swift">
{`let opts = StatsigOptions(overrideStableID: "my_stable_id")
Statsig.start(sdkKey: "client-xyx", options: opts)
Statsig.initialize(sdkKey: "client-xyx", options: opts)
`}
</CodeBlock>
);
16 changes: 8 additions & 8 deletions docs/client/iOS/_statsigListening.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ 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().
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.

Expand Down Expand Up @@ -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 */ }
}
```
Loading