Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swift_Kotlin swiftklib interop #10

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
abi_version=1.8.0
builtins_platform=NATIVE
commonizer_native_targets=ios_arm64 ios_simulator_arm64 ios_x64
commonizer_target=(ios_arm64, ios_simulator_arm64, ios_x64)
compiler_version=2.0.20
depends=org.jetbrains.kotlin.native.platform.darwin org.jetbrains.kotlin.native.platform.posix stdlib
exportForwardDeclarations=
includedForwardDeclarations=
interop=true
ir_signature_versions=1,2
metadata_version=1.4.1
native_targets=ios_arm64 ios_simulator_arm64 ios_x64
package=io.github.lilytreasure
unique_name=io.github.lilytreasure\:multiplatformContact-cinterop-ContactsHelper
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ plugins {
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.swiftKlib) apply false
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ coreKtx = "1.13.1"
compose-activity = "1.9.0"
libphonenumber = "8.2.0"
nexus-publish = "2.0.0"
swiftklib = "0.6.3"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
Expand Down Expand Up @@ -46,3 +47,4 @@ jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
swiftKlib = { id = "io.github.ttypic.swiftklib", version.ref = "swiftklib" }
124 changes: 64 additions & 60 deletions iosApp/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

40 changes: 37 additions & 3 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
84BD33712D79ABD3008FF575 /* ContactsHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BD33702D79ABD3008FF575 /* ContactsHelper.swift */; };
BA7E9141DFC9343677956A0B /* Pods_iosApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECDCBB71984EE56B1436CE14 /* Pods_iosApp.framework */; };
/* End PBXBuildFile section */

Expand All @@ -21,6 +22,7 @@
7555FF7B242A565900829871 /* MultiplatformContacts.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MultiplatformContacts.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
84BD33702D79ABD3008FF575 /* ContactsHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsHelper.swift; sourceTree = "<group>"; };
AB3632DC29227652001CCB65 /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
C4D5CF14F93DD2DD36CCF4C7 /* Pods-iosApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.debug.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.debug.xcconfig"; sourceTree = "<group>"; };
EAE45C34512C71B475E5A58E /* Pods-iosApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.release.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -78,6 +80,7 @@
7555FF7D242A565900829871 /* iosApp */ = {
isa = PBXGroup;
children = (
84BD336F2D79ABA4008FF575 /* contacts */,
058557BA273AAA24004C7B11 /* Assets.xcassets */,
7555FF82242A565900829871 /* ContentView.swift */,
7555FF8C242A565B00829871 /* Info.plist */,
Expand All @@ -87,6 +90,14 @@
path = iosApp;
sourceTree = "<group>";
};
84BD336F2D79ABA4008FF575 /* contacts */ = {
isa = PBXGroup;
children = (
84BD33702D79ABD3008FF575 /* ContactsHelper.swift */,
);
path = contacts;
sourceTree = "<group>";
};
983B9268D3930DE50EA2605E /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -115,6 +126,7 @@
7555FF77242A565900829871 /* Sources */,
B92378962B6B1156000C7307 /* Frameworks */,
7555FF79242A565900829871 /* Resources */,
115BE6A326DB5A1AC9B771B3 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -171,6 +183,23 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
115BE6A326DB5A1AC9B771B3 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n";
showEnvVarsInLog = 0;
};
CB7345DB5F2E35566B2E17F9 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -209,7 +238,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd \"$SRCROOT/../..\"\n./gradlew :sample:common:embedAndSignAppleFrameworkForXcode\n";
shellScript = "cd \"$SRCROOT/../..\"\n./gradlew :multiplatformContact:embedAndSignPodAppleFrameworkForXcode\n";
};
/* End PBXShellScriptBuildPhase section */

Expand All @@ -218,6 +247,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
84BD33712D79ABD3008FF575 /* ContactsHelper.swift in Sources */,
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
7555FF83242A565900829871 /* ContentView.swift in Sources */,
);
Expand Down Expand Up @@ -354,7 +384,9 @@
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = 9Z5F72MRRD;
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)\n$(SRCROOT)/../common/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)\n$(SRCROOT)/../common/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
);
INFOPLIST_FILE = iosApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -384,7 +416,9 @@
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = "${TEAM_ID}";
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)\n$(SRCROOT)/../common/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)";
FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)\n$(SRCROOT)/../common/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
);
INFOPLIST_FILE = iosApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
19 changes: 19 additions & 0 deletions iosApp/iosApp/contacts/ContactsHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// ContactsHelper.swift
// iosApp
//
// Created by Admin on 06/03/2025.
// Copyright © 2025 orgName. All rights reserved.
//
import SwiftUI

@objc public class ContactsHelper: NSObject {
@objc public override init() {
super.init()
}

@objc public func loadContacts(){
print("Contacts loader invoked")
}

}
26 changes: 21 additions & 5 deletions multiplatformContact/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ plugins {
kotlin("native.cocoapods")
id("com.vanniktech.maven.publish") version "0.28.0"
alias(libs.plugins.compose.compiler)
alias(libs.plugins.swiftKlib)
}

swiftklib {
create("ContactsHelper") {
path = file("/Users/admin/StudioProjects/MultiplatformContacts/iosApp/iosApp/contacts")
packageName("io.github.lilytreasure")
minIos = 14
}
}
kotlin {
androidTarget {
compilations.all {
Expand All @@ -19,21 +27,29 @@ kotlin {
publishLibraryVariants("release", "debug")
}

iosX64()
iosArm64()
iosSimulatorArm64()
val iosTargets = listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
)

// iosTargets.forEach { target ->
// target.compilations["main"].cinterops {
// create("ContactsHelper")
// }
// }

cocoapods {
version = "1.0.0"
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
ios.deploymentTarget = "14.0"
podfile = project.file("../iosApp/Podfile") // why doesn't it load the cocoapods from the iosApp podfile?
podfile = project.file("../iosApp/Podfile") // ✅ This will load your Podfile correctly
framework {
baseName = "shared"
isStatic = true
}
}

sourceSets {

androidMain.dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package multiContacts

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Contacts.CNContact
import platform.ContactsUI.CNContactPickerDelegateProtocol
import platform.ContactsUI.CNContactPickerViewController
Expand All @@ -22,6 +23,9 @@ actual fun pickMultiplatformContacts(
countryISOCode: String,
onResult: ContactPickedCallback
): Launcher {
//Contacts helper
// val contacts=ContactsHelper()
// contacts.loadContacts()
val launcherCustom = remember {
Launcher(onLaunch = {
val picker = CNContactPickerViewController()
Expand Down