# Getting Started with Swift

<SkillCard title="AI Skill" subtitle="openfort-xyz/swift-sdk" source="github" subtitleHref="https://github.com/openfort-xyz/swift-sdk" description="Pre-built prompt with the full setup reference." content={skillContent} fileName="SKILL.md" />

## Installation

::::steps

### Create an iOS Project

To get started using Openfort with iOS, create a new project in Xcode. Select Swift as your language. See the [Xcode documentation](https://developer.apple.com/documentation/xcode/creating-an-xcode-project-for-an-app) for more information.

### Install the Openfort iOS SDK

Follow the [Swift Package Manager](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app) instructions to install Openfort as a dependency. When prompted for the package URL, enter `https://github.com/openfort-xyz/swift-sdk.git`. Be sure to add the package to your target.

### Set up auth providers

Navigate to the **auth providers** page on the [Openfort dashboard](https://dashboard.openfort.io) by selecting your project and clicking Auth Providers Methods in the side bar in the [users page](https://dashboard.openfort.io/players). Select the account types you'd like users to be able to login with.

::::

## Set up

Before you begin, make sure you have set up your **publishable key** app from the Openfort Dashboard.
:::warning
A properly set up publishable key is required for mobile apps and other non-web platforms to allow your app to interact with the Openfort API. Please follow [this guide](/docs/configuration/native-apps) to configure an app client.
:::

::::steps

### Import the Framework

```swift
import OpenfortSwift
```

### Get your Openfort keys

From the [Openfort Dashboard](https://dashboard.openfort.io), select your desired app and navigate to the [developers page](https://dashboard.openfort.io/api-keys). You'll need:

* **Publishable Key**: Safe to expose in client-side environment
* **Secret Key**: Must be kept secure and used only server-side
* **Shield Keys**: Required for non-custodial wallets
  * Create Shield keys in the Shield section
  * Securely store the encryption share shown in the one-time popup
  * You'll get both a Publishable and Secret Shield key

### Configure [OFConfig.plist](https://github.com/openfort-xyz/swift-sdk/blob/main/OFConfig.plist)

1. Download the OFConfig.plist and add it to your Xcode project.
2. Make sure to select “Copy items if needed” when prompted.
3. Open the file in Xcode and configure the following keys with your values:

* `openfortPublishableKey` – Your Openfort publishable key (required)
* `shieldPublishableKey` – Your Shield publishable key (required)

### Enable Keychain access

The SDK stores all session state in the iOS Keychain, so your app must be able to use it. In your target's **Signing & Capabilities** tab, add the **Keychain Sharing** capability.

:::warning
On the **iOS Simulator**, run a *signed* build. An unsigned target cannot access the Keychain (`errSecMissingEntitlement`, -34018), and `setupSDK()` will throw `OFError.keychainInaccessible`.
:::

### Initialize the SDK

In your `AppDelegate.swift`:

```swift
import UIKit
import OpenfortSwift

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        do {
            try OFSDK.setupSDK()
        } catch {
            print("Failed to initialize Openfort SDK: \(error)")
        }
        return true
    }
}
```

:::note
`setupSDK()` is a throwing function. You can also pass optional parameters for third-party authentication:

```swift
try OFSDK.setupSDK(thirdParty: OFAuthProvider? = nil, getAccessToken: (() async throws -> String?)? = nil)
```

:::

### Wait until the SDK is ready

`setupSDK()` returns *before* the embedded WebView bridge has finished loading, so wait for it before your first SDK call:

```swift
try await OFSDK.shared.waitUntilReady()
// ...now safe to authenticate, configure the wallet, etc.
```

You can also observe the `.openfortReady` notification (`.openfortInitError` on failure).

::::

## Next Steps

Now that you've configured your app, you can use `OFSDK.shared` throughout to access the Openfort SDK.

### Authenticate your users

Every flow returns an embedded-wallet-backed session. Pick the ones that fit your app:

* [Email & password / OTP](/docs/products/embedded-wallet/swift/auth/email)
* [Sign in with Apple](/docs/products/embedded-wallet/swift/auth/sign-in-with-apple) and [other OAuth providers](/docs/products/embedded-wallet/swift/auth/oauth)
* [Guest mode](/docs/products/embedded-wallet/swift/auth/guest) for instant onboarding
* [External wallets (SIWE)](/docs/products/embedded-wallet/swift/auth/external-wallet)
* [Your own auth provider](/docs/products/embedded-wallet/swift/auth/third-party) (Firebase, Supabase, OIDC, custom)

### Set up the wallet

When you [set up a wallet](/docs/products/embedded-wallet/swift/wallet/recovery), choose an
[account type](/docs/products/embedded-wallet/account-types) — a **Smart Account**
(`accountType: .smartAccount`) is the simplest way to get **gasless, sponsored transactions** with
batching. See [Sponsored (gasless) transactions](/docs/products/embedded-wallet/swift/wallet/eip-7702).

<HoverCardLink
  description="View our swift sample. A minimal installation of the Openfort SDK for Swift."
  href="https://github.com/openfort-xyz/swift-example"
  title="View sample"
  subtitle="Swift Sample"
  img={{
  src: "/img/icons/swift-icon.svg",
  alt: "View sample",
}}
  color="#F7DF1E"
/>
