Maybe basic question and it's based off something ...
# compose-ios
c
Maybe basic question and it's based off something I asked a few months ago, but I'm coming back to kmp again and basically I saw that you can do this to open a browser in iOS:
Copy code
val nsUrl = NSURL.URLWithString(url)
if (UIApplication.sharedApplication.canOpenURL(nsUrl!!)) {
  UIApplication.sharedApplication.openURL(nsUrl)
}
Am I understanding this right... that this is kotlin code... but it's accessing apple/iOS framework code? I didn't know that was possible. I was doing this in swift
Copy code
func openInBrowser(url: String) {
        #if os(iOS)
            UIApplication.shared.open(URL(string: url)!)
        #endif

        #if os(macOS)
            NSWorkspace.shared.open(URL(string: url)!)

        #endif
    }
👌 1
j
this is kotlin code... but it's accessing apple/iOS framework code
this is entire function of the cinterop tool for Kotlin (and by extension, the C calling convention for any language)
c
idk how i missed this. i thought kmp (even without compose) was for kotlin to be compiled to objc. but this way, it looks like objc code can be called in kotlin. how the heck did i miss this "feature" 🤦
j
Kotlin does not compile to objective c
2
Kotlin compiles to native code through LLVM
👍 1
It can talk to other languages through C headers which the cinterop tool takes and generates Kotlin "headers"
Inversely, other languages can call into Kotlin through the C calling convention, and you can expose C headers of Kotlin code for other languages to consume
👍 1
c
oh. thanks for teaching. still feel out of my comfort zone. been doing android/java for too long. is there like a way to see what Objc stuff I can call through kotlin? or is pretty much everything in apple/ios sdk is avail through kotlin.
also. if it doesn't compile into objc... and instead into native. what's this whole thing about consuming kmp code (non-compose) in ios is an obj-c library, and in the future they're saying they'll make it swift?
j
Kotlin generates C headers that have objective c annotations to add sugar for objective c callers
Yes you can generally call anything by Apple that's written in C or objective C
😊 1
c
thanks. i dont think i "really" know what headers are. so ill look into that quick. from context clues. headers kinda just seem like a table of contents, and not the actual contents.
Kotlin generates C headers that have objective c annotations to add sugar for objective c callers
and if im on the right path with what headers are. then it'd seem like generating c headers with swift annotations would be "easy", no?
j
Headers are the public API signatures
👍 1
So Kotlin already puts annotations into the C header for Swift
The problem is that Swift is a very powerful language and C simply cannot express enough detail to make the Swift API nice
❤️ 2
👌 1