Basic Configuration

Add this to your App file (typically App.swift):
import SuggestKit
import SwiftUI

@main
struct MyApp: App {
    init() {
        // Configure SuggestKit with your public API key
        SuggestKit.configure(
            apiKey: "your_public_api_key_here",
            environment: .production // or .sandbox for testing
        )
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

API Key Setup

  1. Get your API key from the SuggestKit Dashboard
  2. Use your public key (starts with public_) - never use the secret key in mobile apps
  3. Store securely in your app’s configuration
Never expose your secret API key in client-side code. Only use the public key for mobile SDKs.

Environment Configuration

Production Environment

SuggestKit.configure(
    apiKey: "public_your_production_key",
    environment: .production
)

Sandbox Environment

Use sandbox for testing and development:
SuggestKit.configure(
    apiKey: "public_your_sandbox_key", 
    environment: .sandbox,
    debugMode: true // Enable detailed logging
)

Advanced Configuration

SuggestKit.configure(
    apiKey: "your_public_api_key",
    environment: .production,
    options: SuggestKitOptions(
        // Network settings
        requestTimeout: 30.0,
        maxRetries: 3,
        
        // Caching
        enableOfflineCache: true,
        maxCacheSize: 50, // suggestions
        
        // UI defaults
        defaultTheme: .system,
        enableHaptics: true,
        
        // Analytics
        enableAnalytics: true,
        
        // Debug
        debugMode: false
    )
)

User Management

Set Current User

Call this after user authentication:
import SuggestKit

// Basic user setup
SuggestKit.setUser(
    id: "user_12345",
    email: "user@example.com"
)

// Advanced user setup
SuggestKit.setUser(
    id: "user_12345",
    email: "user@example.com",
    customId: "my_internal_user_id",
    monthlyRevenue: 19.99,
    country: "US",
    platform: .ios,
    locale: "en_US",
    metadata: [
        "plan": "pro",
        "signup_date": "2024-01-15"
    ]
)

Clear User Session

// On logout
SuggestKit.clearUser()

Configuration Validation

Verify your setup with debug mode:
#if DEBUG
SuggestKit.configure(
    apiKey: "your_api_key",
    environment: .sandbox,
    debugMode: true
)

// This will log configuration status
SuggestKit.validateConfiguration()
#endif

Error Handling

Handle configuration errors gracefully:
do {
    try SuggestKit.configure(
        apiKey: "your_api_key",
        environment: .production
    )
} catch SuggestKitError.invalidAPIKey {
    print("Invalid API key provided")
} catch SuggestKitError.networkError(let details) {
    print("Network configuration error: \(details)")
} catch {
    print("Configuration error: \(error)")
}

Next Steps