An Objective-C wrapper for FirebaseAILogic (Vertex AI in Firebase), designed specifically to be consumed by Kotlin Multiplatform (KMP) via cinterop.
Pure Swift libraries cannot be directly used in Kotlin Multiplatform cinterop. Swift's classes, generics, and async/await patterns are not compatible with the Objective-C runtime that Kotlin Native relies on for interoperability.
This library wraps Swift APIs into NSObject subclasses, making them accessible from Kotlin Native through cinterop. All public APIs are exposed as Objective-C-compatible classes with the KFB prefix.
- Swift 5.9+ / Xcode 15+
- iOS 15.0+
- macOS 10.15+
- Mac Catalyst 15.0+
- tvOS 15.0+
- watchOS 7.0+
Add the following to your Package.swift dependencies:
dependencies: [
.package(url: "https://github.com/uny/firebase-objc-sdk.git", from: "0.1.0")
]Then add FirebaseAILogicObjC to your target dependencies:
.target(
name: "YourTarget",
dependencies: [
.product(name: "FirebaseAILogicObjC", package: "firebase-objc-sdk")
]
)Note: This library is typically not installed directly in an iOS app. Instead, it is added to your Kotlin Multiplatform project's Gradle setup or a local Swift package for cinterop.
This library bridges Firebase AI from Swift to Kotlin through Objective-C:
Swift (FirebaseAILogic) → Objective-C (FirebaseAILogicObjC) → Kotlin Native (via cinterop)
GenerativeModel → KFBGenerativeModel → GenerativeModel
Content → KFBContent → Content
GenerateContentResponse → KFBGenerateContentResponse → GenerateContentResponse
// In your KMP shared module, after setting up cinterop:
val firebaseAI = KFBFirebaseAI.vertexAI()
val model = firebaseAI.generativeModel(modelName = "gemini-2.0-flash")
val response = model.generateContent("Hello, how are you?")
println(response.text)The library provides Objective-C wrappers for the following Firebase AI types:
KFBFirebaseAI- Main entry point for Firebase AIKFBGenerativeModel- Generative model for content generationKFBChat- Chat session managementKFBContent/KFBContentBuilder- Content building utilitiesKFBGenerateContentResponse- Response from content generationKFBCandidate- Response candidateKFBModelContent- Model content representationKFBPart/KFBTextPart/KFBInlineDataPart- Content partsKFBCitation/KFBCitationMetadata- Citation informationKFBGenerationConfig- Generation configurationKFBSafetyRating/KFBSafetySetting- Safety controls- And more...
| firebase-objc-sdk | firebase-ios-sdk |
|---|---|
| 0.1.0 | 12.8.0 |
This library's version is independent of the underlying firebase-ios-sdk version. The table above shows which version of firebase-ios-sdk each release wraps.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.