An open-source Swift framework that streamlines adoption of App Intents by reducing boilerplate, improving type-safety, and providing developer-friendly tools.
- 70%+ Boilerplate Reduction: Dramatically reduce the code needed to implement App Intents
- Type-Safe Parameter Handling: Built-in helpers for parameter extraction and validation
- Code Generation: Generate intent definitions from simple YAML/JSON schemas
- Comprehensive Testing: XCTest integration with 95%+ coverage
- Performance Optimized: Average intent resolution under 10ms
Add IntentKit to your Package.swift:
dependencies: [
.package(url: "https://github.com/realtobyfu/IntentKit.git", from: "1.0.0")
]import IntentKit
import AppIntents
struct SendMessageIntent: AppIntent {
static var title: LocalizedStringResource = "Send Message"
@Parameter(title: "Recipient")
var recipient: String?
@Parameter(title: "Message")
var message: String?
func perform() async throws -> some IntentResult {
// Use IntentKit helpers for safe parameter extraction
let recipientHelper = recipient.withHelper(defaultValue: "Unknown")
let messageText = try message.withHelper().requireValue()
// Your intent logic here
await sendMessage(to: recipientHelper.value()!, text: messageText)
return .result()
}
}Create a schema file (intents.yaml):
version: "1.0"
intents:
- name: CreateNoteIntent
description: Create a new note
category: productivity
parameters:
- name: title
type: String
description: Note title
isOptional: false
- name: content
type: String
description: Note content
isOptional: false
- name: tags
type: "[String]"
description: Optional tags
isOptional: true
defaultValue: "[]"Generate Swift code:
swift run intentkit-gen intents.yaml --output ./Generatedimport IntentKit
// Simple donation
let intent = CreateNoteIntent()
intent.title = "Shopping List"
intent.content = "Milk, Eggs, Bread"
try await IntentDonationManager.shared.donate(intent)
// Batch donation with builder pattern
let intents = notes.map { note in
IntentDonationBuilder(intent: CreateNoteIntent())
.with(keyPath: \.title, value: note.title)
.with(keyPath: \.content, value: note.content)
.build()
}
try await IntentDonationManager.shared.donateBatch(intents)let executor = IntentExecutor(
intent: myIntent,
configuration: ExecutionConfiguration(
timeout: 30.0,
retryCount: 3,
retryDelay: 1.0
)
)
let result = try await executor.executeWithRetry()IntentKit provides comprehensive testing utilities:
import XCTest
import IntentKit
class MyIntentTests: XCTestCase {
func testIntentExecution() async throws {
let intent = SendMessageIntent()
intent.recipient = "John"
intent.message = "Hello"
let expectation = IntentExpectation<SendMessageIntent> { intent, result in
XCTAssertEqual(intent.recipient, "John")
}
let testExecutor = IntentTestExecutor(
intent: intent,
expectations: [expectation]
)
let result = try await testExecutor.runTest()
XCTAssertTrue(result.success)
}
}IntentKit is optimized for performance with:
- Average parameter resolution < 10ms
- Efficient batch donation processing
- Minimal metrics recording overhead
- Constant-time parameter access
IntentParameterHelper<T>: Type-safe wrapper for intent parametersAsyncParameterResolver<T>: Handle async parameter resolutionRangeValidatedParameter<T>: Validate numeric parameters against rangesParameterExtractor: Extract and validate parameters with fallbacks
IntentDonationManager: Manage intent donations with batchingIntentDonationBuilder: Fluent API for building intentsDonationConfiguration: Configure donation behavior
IntentExecutor: Execute intents with timeout and retryExecutionConfiguration: Configure execution behaviorExecutionMetrics: Track performance metrics
IntentCodeGenerator: Generate Swift code from schemasSchemaParser: Parse YAML/JSON intent definitionsGeneratorConfiguration: Configure code generation
Generate Swift code from intent schemas:
# Generate from YAML
swift run intentkit-gen schema.yaml --output ./Generated
# Generate from JSON
swift run intentkit-gen schema.json --json --output ./Generated
# Skip helper generation
swift run intentkit-gen schema.yaml --skip-helpers
# Validate schema only
swift run intentkit-gen validate schema.yaml --verboseContributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
IntentKit is available under the MIT license. See LICENSE for details.
- iOS 16.0+ / macOS 13.0+ / watchOS 9.0+ / tvOS 16.0+
- Swift 5.9+
- Xcode 15.0+