# iOS Quickstart

**Example Repository**

- [iOS Quickstart Repo](https://github.com/clerk/clerk-ios/tree/main/Examples/Quickstart)

**Before you start**

- [Set up a Clerk application](https://clerk.com/docs/getting-started/quickstart/setup-clerk.md)

1. ## Enable Native API

   In the Clerk Dashboard, navigate to the [**Native applications**](https://dashboard.clerk.com/~/native-applications) page and ensure that the Native API is enabled. This is required to integrate Clerk in your native application.
2. ## Create a new iOS app

   If you don't already have an iOS app, create a new project in Xcode. Select SwiftUI as your interface and Swift as your language.
   See the [Xcode documentation](https://developer.apple.com/documentation/xcode/creating-an-xcode-project-for-an-app) for more information.
3. ## Install the Clerk iOS SDK

   Follow [the Swift Package Manager instructions](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app) to install Clerk as a dependency.
   When prompted for the package URL, enter `https://github.com/clerk/clerk-ios`. Be sure to add both `ClerkKit` and `ClerkKitUI` to your target.
4. ## Add your Native Application

   Add your iOS application to the [**Native applications**](https://dashboard.clerk.com/~/native-applications) page in the Clerk Dashboard. You will need your iOS app's **App ID Prefix** and **Bundle ID**.
5. ## Add associated domain capability

   To enable seamless authentication flows, you need to add an associated domain capability to your iOS app. This allows your app to work with Clerk's authentication services.

   1. In Xcode, select your project in the Project Navigator.
   2. Select your app target.
   3. Navigate to the **Signing & Capabilities** tab.
   4. Select the **+ Capability** option.
   5. Search for and add **Associated Domains**. It will be added as a dropdown to the **Signing & Capabilities** tab.
   6. Under **Associated Domains**, add a new entry with the value: `webcredentials:{YOUR_FRONTEND_API_URL}`

   > Replace `{YOUR_FRONTEND_API_URL}` with your Frontend API URL.
6. ## Configure Clerk

   Configure Clerk once at app launch and provide it to your SwiftUI environment.

   1. Inside your new project in Xcode, open your `@main` app file.
   2. Import `ClerkKit`.
   3. Configure Clerk with your Clerk Publishable Key in your app's initializer.
   4. Inject `Clerk.shared` into the SwiftUI environment using `.environment(Clerk.shared)` so your views can access it.

   ```swift {{ filename: 'ClerkQuickstartApp.swift', mark: [2, [6, 8], 13] }}
   import SwiftUI
   import ClerkKit

   @main
   struct ClerkQuickstartApp: App {
     init() {
       Clerk.configure(publishableKey: "{{pub_key}}")
     }

     var body: some Scene {
       WindowGroup {
         ContentView()
           .environment(Clerk.shared)
       }
     }
   }
   ```
7. ## Conditionally render content

   To render content based on whether a user is authenticated or not:

   1. Open your `ContentView` file.
   2. Import `ClerkKit` and access the shared `Clerk` instance that you injected into the environment in the previous step.
   3. Replace the content of the view body with a conditional that checks for a `clerk.user`.

   ```swift {{ filename: 'ContentView.swift', mark: [2, 5, [8, 14]] }}
   import SwiftUI
   import ClerkKit

   struct ContentView: View {
     @Environment(Clerk.self) private var clerk

     var body: some View {
       VStack {
         if let user = clerk.user {
           Text("Hello, \(user.id)")
         } else {
           Text("You are signed out")
         }
       }
     }
   }
   ```
8. ## Use Clerk's prebuilt views

   Clerk provides prebuilt SwiftUI views that handle authentication flows and user management, eliminating the need to build custom forms and flows.

   Update your `ContentView` to use two key Clerk's prebuilt views:

   - [`AuthView`](https://clerk.com/docs/ios/reference/views/authentication/auth-view.md): A comprehensive authentication view that handles sign-in and sign-up flows, including email verification, password reset, and multi-factor authentication. It's presented as a sheet when the user taps "Sign in".

   - [`UserButton`](https://clerk.com/docs/ios/reference/views/user/user-button.md): A circular button that displays the user's profile image. When tapped, it automatically presents the [`UserProfileView`](https://clerk.com/docs/ios/reference/views/user/user-profile-view.md) where users can manage their account, update their profile, and sign out.

   Replace the existing content with the following code. Import both `ClerkKit` and `ClerkKitUI` when using prebuilt views:

   ```swift {{ filename: 'ContentView.swift', mark: [[2, 3], 6, [10, 14], [16, 19]] }}
   import SwiftUI
   import ClerkKit
   import ClerkKitUI

   struct ContentView: View {
     @State private var authIsPresented = false

     var body: some View {
       VStack {
         UserButton(signedOutContent: {
           Button("Sign in") {
             authIsPresented = true
           }
         })
       }
       .prefetchClerkImages()
       .sheet(isPresented: $authIsPresented) {
         AuthView()
       }
     }
   }
   ```
9. ## Run your project

   In Xcode, select `Run ▶︎` to build and launch the app.
10. ## Create your first user

    Once the app launches successfully, tap "Sign in" and the `AuthView` will appear, allowing you to sign up or sign in to create your first user.

## Next steps

Learn more about Clerk views, how to customize them, and explore the Clerk iOS SDK using the following guides.

- [Prebuilt views](https://clerk.com/docs/ios/reference/views/overview.md): Learn how to quickly add authentication to your app using Clerk's suite of views.
- [Customization with ClerkTheme](https://clerk.com/docs/ios/guides/customizing-clerk/clerk-theme.md): Learn how to customize Clerk views using&#x20;
- [Add native Sign in with Apple](https://clerk.com/docs/guides/configure/auth-strategies/sign-in-with-apple.md): Learn how to add native Sign in with Apple to your Clerk apps on Apple platforms.
- [Clerk iOS SDK Reference](https://clerk.com/docs/reference/native-mobile/overview.md): Learn about the Clerk iOS SDK and how to integrate it into your app.

---

## Sitemap

[Overview of all docs pages](https://clerk.com/docs/llms.txt)
