> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloneable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Initialize and authenticate

> Initialize the Cloneable SDK and authenticate

<Info>
  The Cloneable SDK uses SwiftUI. For UIKit apps, use a `UIHostingController`.
</Info>

## Initialize the SDK

Initialize one `CloneablePlatform` instance as a `StateObject`.

#### Set authentication parameters

Set `authType` to `.api`.

Provide an API key. API key authentication grants its associated permissions.

<Info>
  Create an API key in [API keys](https://app.cloneable.ai/settings/api-keys).
</Info>

JWT authentication is unsupported. Use API key authentication.

```swift theme={null}
import CloneablePlatformiOS

@main
struct Example_App: App {
    // CloneablePlatform conforms to ObservableObject
    @StateObject private var cloneable: CloneablePlatform = CloneablePlatform(authType: .api, apiKey: "YOUR_API_KEY")
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(cloneable) // Pass the SDK reference as an environment object
        }
    }
}
```

### Pass the SDK to child views

Pass the SDK through the view hierarchy as an environment object. Child views can then access it:

```swift theme={null}
struct ChildView: View {
    @EnvironmentObject var cloneable: CloneablePlatform
    ...
}
```

## Authenticate

The SDK exposes properties and helpers for authentication status.

### API based auth

Pass your API key to the `CloneablePlatform` initializer.

### Auth status

Read `userAuthed` from `CloneablePlatform` to determine whether the user is authenticated.

For example:

```swift theme={null}
struct ChildView: View {
    @EnvironmentObject var cloneable: CloneablePlatform
    
    var body: some View {
        Group {
            switch cloneable.authStatus {
            case .authenticated:
                MainAppView()
            case .not_authenticated:
                Text("Not authenticated")
            case .loading:
                ProgressView("Authenticating...")
            }
        }
    }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.