Skip to main content
Before you begin, make sure you have:
  • iOS 15.0+ - The SDK requires iOS 15.0 or later
  • Swift 5.9+ - Modern Swift features are used throughout
  • Xcode 14.0+ - For the best development experience
  • Dynamic Account - Set up your project and get an environment ID from Dynamic Dashboard

Install the SDK

Configure URL Scheme

Add a URL scheme to your Info.plist for authentication callbacks:
Info.plist
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.yourcompany.yourapp</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>yourapp</string>
        </array>
    </dict>
</array>

Initialize the SDK

Configuration Options

PropertyDescriptionRequired
environmentIdYour Dynamic environment ID from the dashboardYes
appLogoUrlURL to your app’s logo (shown in auth UI)Yes
appNameYour app’s display nameYes
redirectUrlDeep link URL scheme for callbacksYes
appOriginYour app’s origin URLYes
logLevelLogging level (.debug, .info, .warn, .error)No
debugDebug options like ClientDebugProps(webview: true)No

Access the SDK

After initialization, access the SDK singleton anywhere in your app:
let sdk = DynamicSDK.instance()

Basic Usage

Using Built-in Authentication UI

The easiest way to add authentication is using the built-in UI:
import SwiftUI
import DynamicSDKSwift

struct ContentView: View {
    var body: some View {
        VStack {
            Button("Sign In") {
                DynamicSDK.instance().ui.showAuth()
            }
        }
    }
}

Listening for Authentication State

Use Combine publishers to react to authentication changes:
import SwiftUI
import DynamicSDKSwift
import Combine

struct ContentView: View {
    @StateObject private var vm = ContentViewModel()

    var body: some View {
        Group {
            if vm.isAuthenticated {
                HomeView()
            } else {
                LoginView()
            }
        }
    }
}

@MainActor
class ContentViewModel: ObservableObject {
    @Published var isAuthenticated = false
    private let sdk = DynamicSDK.instance()
    private var cancellables = Set<AnyCancellable>()

    init() {
        // Check initial auth state
        isAuthenticated = sdk.auth.authenticatedUser != nil

        // Listen for auth state changes
        sdk.auth.authenticatedUserChanges
            .receive(on: DispatchQueue.main)
            .sink { [weak self] user in
                self?.isAuthenticated = user != nil
            }
            .store(in: &cancellables)
    }
}

Complete Example with Wallets

import SwiftUI
import DynamicSDKSwift
import Combine

struct HomeView: View {
    @State private var wallets: [BaseWallet] = []
    @State private var cancellables = Set<AnyCancellable>()

    private let sdk = DynamicSDK.instance()

    var body: some View {
        VStack {
            Text("Welcome!")

            ForEach(wallets, id: \.address) { wallet in
                Text("Wallet: \(wallet.address)")
            }

            Button("Show Profile") {
                sdk.ui.showUserProfile()
            }

            Button("Logout") {
                Task {
                    try await sdk.auth.logout()
                }
            }
        }
        .onAppear {
            // Get current wallets
            wallets = sdk.wallets.userWallets

            // Listen for wallet changes
            sdk.wallets.userWalletsChanges
                .receive(on: DispatchQueue.main)
                .sink { newWallets in
                    wallets = newWallets
                }
                .store(in: &cancellables)
        }
    }
}

Enable Features in Dashboard

Before you can use authentication and wallet features, enable them in your Dynamic dashboard:
  1. Go to your Dynamic Dashboard
  2. Select your project
  3. Go to Authentication and enable the methods you want to use:
    • Email OTP
    • SMS OTP
    • Social providers (Apple, Google, Farcaster)
    • Passkeys
  4. Go to Wallets and enable embedded wallets
  5. Go to Chains and enable the networks you want to support (EVM and/or Solana)
For testing, we recommend starting with Email OTP authentication and an EVM testnet like Base Sepolia. This gives you a complete setup without requiring real phone numbers or mainnet transactions.

Troubleshooting

Common Issues

  • Could not find module ‘DynamicSDKSwift’
    • Make sure you’ve added the package to your target
    • Try cleaning the build folder (Product → Clean Build Folder)
    • Restart Xcode
  • SDK not initialized
    • Ensure DynamicSDK.initialize() is called in your App’s init() before any views access the SDK
    • Don’t call DynamicSDK.instance() before initialization
  • Authentication callbacks not working
    • Verify your URL scheme is configured in Info.plist
    • Ensure the redirectUrl matches your URL scheme
    • Whitelist your deep link URL in the Dynamic dashboard under Security → Whitelist Mobile Deeplink
  • Wallets not appearing after login
    • Wallets are created asynchronously after authentication
    • Use sdk.wallets.userWalletsChanges publisher to listen for wallet updates
    • Check that embedded wallets are enabled in your dashboard
  • Session state not updating
    • Make sure you’re observing the reactive Combine publishers (authenticatedUserChanges, userWalletsChanges, etc.)
    • Verify that your views are using @StateObject or @ObservedObject for view models that observe SDK state

What’s Next

Great! Your SDK is now configured and ready to use. Here’s what you can do next:
  1. Authentication Guide - Learn how to implement user authentication with email, SMS, and passkeys
  2. Social Authentication - Add social login options like Apple, Google, and Farcaster
  3. Wallet Operations - Work with balances and sign messages
  4. Networks - Configure blockchain networks
📱 Complete Example App: For a fully functional iOS app demonstrating all SDK features, check out our Swift SDK Example App. It includes authentication flows (email/SMS OTP, social login, passkeys), wallet management, EVM/Solana transactions, MFA, and passkey examples with SwiftUI.