This is a minimalist sample of a Kotlin Multiplatform Library using Apollo Android 2.
It contains 2 modules:
utils
- Defines a
Platform
class withexpect
/actual
for iOS and Android - Contains GraphQL schema (for https://apollo-fullstack-tutorial.herokuapp.com/) + one operation
- Defines a
mympplibrary
- Defines a
MyMppLibrary
class, with one function usingPlatform
and one function making a GraphQL call using the generated code fromutils
- Defines a
To use:
./gradlew assemble
- Have an XCode project
- Drag and drop
mympplibrary/build/fat-framework/debug/MyMppLibrary.framework
from the Finder to the XCode project in theFrameworks
folder of your project in the left pane - In the
yourproject.xcodeproj
of your app, inFrameworks, Libraries and Embedded Content
, forMyMppLibrary.framework
, chooseEmbed without Signing
Here's an example of a minimalist Swift app using the library:
// MySuperAppApp.swift
import SwiftUI
import MyMppLibrary
@main
struct MySuperAppApp: App {
init() {
useMyMppLibrary()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
func useMyMppLibrary() {
setbuf(__stdoutp, nil)
let library = MyMppLibrary()
library.printPlatform()
library.executeSampleQuery { result, _ in
print(result)
}
}
To make things easier, an XCode project is available in the XCode
folder.