Skip to content

uny/firebase-objc-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

firebase-objc-sdk

Swift Package Manager Platform License

An Objective-C wrapper for FirebaseAILogic (Vertex AI in Firebase), designed specifically to be consumed by Kotlin Multiplatform (KMP) via cinterop.

Why This Library Exists

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.

Requirements

  • Swift 5.9+ / Xcode 15+
  • iOS 15.0+
  • macOS 10.15+
  • Mac Catalyst 15.0+
  • tvOS 15.0+
  • watchOS 7.0+

Installation

Swift Package Manager

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.

Usage

Bridge Architecture

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

Kotlin Example (Pseudo-code)

// 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)

Wrapped Classes

The library provides Objective-C wrappers for the following Firebase AI types:

  • KFBFirebaseAI - Main entry point for Firebase AI
  • KFBGenerativeModel - Generative model for content generation
  • KFBChat - Chat session management
  • KFBContent / KFBContentBuilder - Content building utilities
  • KFBGenerateContentResponse - Response from content generation
  • KFBCandidate - Response candidate
  • KFBModelContent - Model content representation
  • KFBPart / KFBTextPart / KFBInlineDataPart - Content parts
  • KFBCitation / KFBCitationMetadata - Citation information
  • KFBGenerationConfig - Generation configuration
  • KFBSafetyRating / KFBSafetySetting - Safety controls
  • And more...

Versioning

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.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

Objective-C (@objc) wrapper for FirebaseAILogic, distributed as a Swift Package so Kotlin Multiplatform projects can consume it via cinterop.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages