| name | astralform-ios-setup |
| description | Integrate Astralform iOS SDK into Swift/SwiftUI projects. Use when user asks to "add Astralform", "integrate Astralform SDK", "setup Astralform in iOS app", or "configure Astralform Swift client". Use when this capability is needed. |
| metadata | {"author":"astralform-ai"} |
Astralform iOS SDK Integration
This skill automates the integration of the Astralform iOS SDK into Swift projects.
When to Use
- User asks to add/integrate Astralform SDK
- User wants to set up AI chat in their iOS app
- User needs to configure Astralform in a Swift/SwiftUI project
- User mentions "Astralform iOS", "Astralform Swift", or "Astralform SDK"
Prerequisites
Before integration, ensure:
- User has an Astralform project with an API key
- Xcode project exists with Swift Package Manager or CocoaPods
- Minimum iOS deployment target is 15.0+
Integration Steps
Step 1: Detect Project Type
Look for these files to determine dependency manager:
Package.swift → Swift Package Manager
Podfile → CocoaPods
*.xcodeproj without above → Manual/SPM via Xcode
Step 2: Add Dependency
For Swift Package Manager (Package.swift):
dependencies: [
.package(url: "https://github.com/astralform/astralform-ios.git", from: "1.0.0")
]
For CocoaPods (Podfile):
pod 'Astralform', '~> 1.0'
For Xcode SPM:
Instruct user to:
- File → Add Package Dependencies
- Enter:
https://github.com/astralform/astralform-ios.git
- Select version rule: Up to Next Major
Step 3: Find App Entry Point
Search for the app entry point:
- SwiftUI: Look for
@main struct with App protocol
- UIKit: Look for
AppDelegate class with @main or @UIApplicationMain
Common patterns:
@main
struct MyApp: App { ... }
@main
class AppDelegate: UIResponder, UIApplicationDelegate { ... }
Step 4: Add Configuration Code
SwiftUI App:
import Astralform
@main
struct MyApp: App {
init() {
Astralform.configure(
apiKey: "YOUR_API_KEY",
baseURL: URL(string: "https://api.astralform.ai")!
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
UIKit AppDelegate:
import Astralform
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
Astralform.configure(
apiKey: "YOUR_API_KEY",
baseURL: URL(string: "https://api.astralform.ai")!
)
return true
}
}
Step 5: Add Chat View
SwiftUI integration:
import SwiftUI
import Astralform
struct ContentView: View {
@State private var showChat = false
var body: some View {
Button("Open AI Chat") {
showChat = true
}
.sheet(isPresented: $showChat) {
AstralformChatView(
endUserId: "user_123",
systemPrompt: "You are a helpful assistant."
)
}
}
}
UIKit integration:
import UIKit
import Astralform
class ViewController: UIViewController {
@IBAction func openChat(_ sender: Any) {
let chatVC = AstralformChatViewController(
endUserId: "user_123",
systemPrompt: "You are a helpful assistant."
)
present(chatVC, animated: true)
}
}
Step 6: Configure Client MCP Tools (Optional)
If the project uses client-side MCP tools (calendar, contacts, etc.):
import Astralform
Astralform.registerClientTool("calendar_events") { parameters async throws -> ToolResult in
let events = try await fetchCalendarEvents(parameters)
return .success(events)
}
Astralform.registerClientTool("add_reminder") { parameters async throws -> ToolResult in
try await addReminder(parameters)
return .success(["status": "created"])
}
Step 7: Provide Test Code
Add a simple test to verify integration:
import Astralform
Task {
do {
let response = try await Astralform.shared.chat(
message: "Hello, are you working?",
endUserId: "test_user"
)
print("AI Response: \(response.content)")
} catch {
print("Error: \(error)")
}
}
Security Best Practices
-
Never hardcode API keys - Use environment variables or secure storage:
let apiKey = ProcessInfo.processInfo.environment["ASTRALFORM_API_KEY"] ?? ""
-
Use different keys for dev/prod:
#if DEBUG
let apiKey = "sk_test_..."
#else
let apiKey = "sk_live_..."
#endif
-
Validate end user IDs - Use authenticated user identifiers
Troubleshooting
| Issue | Solution |
|---|
| "No such module 'Astralform'" | Clean build, reset package caches |
| Network errors | Check API key and baseURL |
| Chat not loading | Verify project has LLM configured |
| Tool calls failing | Check client tool registration |
After Integration
Remind user to:
- Replace
YOUR_API_KEY with actual key from Astralform dashboard
- Set appropriate
endUserId for user tracking
- Configure system prompt for their use case
- Test in both simulator and device
Source: astralform-ai/astralform-plugins — distributed by TomeVault.