https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ios
  • d

    David Winer [G]

    01/08/2021, 6:47 PM
    Hey folks, our UX team is looking to chat with a few iOS developers who work with Kotlin. In particular, people whose primary IDE is Xcode and consider themselves iOS developers but may have to work with Kotlin for shared code from time to time. If anyone in this group fits that description (or you know folks at your company who do), would really appreciate a short 20-30 minute conversation!
    👍 2
    d
    • 2
    • 5
  • d

    darkmoon_uk

    01/11/2021, 11:51 PM
    Anyone have an experience with diagnosing when
    cinterop
    fails for a Cocoapod
    ? No useful output; the Java process exited non-zero 🤷 Knowing what the
    cinterop
    command line executed by
    podImport
    task is, would be a help to start diagnosing/tweaking from the command line. Anyone have an example of 'manually' driving cinterop against a Cocoapod?
    a
    • 2
    • 7
  • d

    darkmoon_uk

    01/16/2021, 3:33 AM
    message has been deleted
    a
    t
    • 3
    • 2
  • p

    phldavies

    01/19/2021, 10:39 AM
    Is there any documentation or examples around using properties from newer iOS versions? We cannot seem to access
    CLLocation.speedAccuracy
    (iOS 10+) or
    CLLocation.courseAccuracy
    (iOS 13.4+) from Kotlin. Ideally we would still support older iOS but utilise
    courseAccuracy
    when on iOS 13.4+ (similar to
    #available
    in swift)
    t
    • 2
    • 6
  • k

    kpgalligan

    01/21/2021, 6:46 PM
    You could probably "fix" the situation by also including SQLCipher in your Podfile for C
    t
    • 2
    • 1
  • p

    Philip Dukhov

    01/24/2021, 3:14 PM
    I have the following code:
    suspend fun pickSystemImage(): ImageContainer =
        suspendCancellableCoroutine { continuation ->
            MainScope().launch {
                NSLog("pickSystemImage MainScope().launch")
                val imagePicker = UIImagePickerController()
                NSLog("pickSystemImage 1")
                // present and handle
            }
        }
    the problem is that initializing
    UIImagePickerController
    takes huge amount of time - around 6 secs, every time.
    2021-01-24 21:56:42.439651+0700 Well[3450:1028035] pickSystemImage MainScope().launch
    2021-01-24 21:56:48.593539+0700 Well[3450:1028035] pickSystemImage 1
    I’ve tried reproducing this in a test project, and there it works fine. I’ve tried switching outer scope, as well as creating scope with main context instead of MainScope, or just without switch to an other scope.. I’m out of the ideas where to look for a solution
    l
    • 2
    • 6
  • t

    Tresa

    02/01/2021, 10:17 AM
    Not able to access isStatic flag. can someone help here?
    r
    • 2
    • 1
  • d

    dazza5000

    02/03/2021, 4:03 PM
    Does anyone have a guide for creating an XCFramework with a kotlin multiplatform project? Something that has arm64 and x86 in the same package?
    l
    • 2
    • 2
  • s

    sushma nayak

    02/04/2021, 4:22 AM
    I’m new to KMM and kotlin but have experience with iOS. Any good guides that you’d recommend to me for easier understanding?
    k
    • 2
    • 3
  • p

    Philip Dukhov

    02/06/2021, 10:20 AM
    I have many enum classes in kotlin, but one of them fore some reason started crashing on iOS:
    object CallFeature {
        data class State {
            enum class Status {
                Calling,
                Incoming,
            }
            enum class ViewPoint {
                Both,
                Self,
                Partner,
            }
        }
    }
    [SharedMobileCallFeatureStateViewPoint partner]: unrecognized selector sent to instance 0x28325adc0. It happens both when I try to compare
    viewPoint == .parent
    or making a
    switch
    I can’t seem to find any diffs with other enums at the same level - those are working well Have anyone faced something similar?
    n
    • 2
    • 4
  • d

    darkmoon_uk

    02/15/2021, 5:29 AM
    EDIT: Resolved; this was due to importing
    serialization-core
    and not
    serialization-json
    as the documentation advises 🙃 . 😞 Help needed... Encountering a nasty crash in the compiler/linker in
    1.4.30
    during either: •
    linkDebugFrameworkIosArm64
    or •
    linkDebugFrameworkIosX64
    (
    compile
    alone, for either platform, succeeds):
    Compilation failed: Unbound symbols not allowed
    More in thread 👉
    y
    i
    +2
    • 5
    • 13
  • a

    Anthony Pages

    02/16/2021, 8:55 AM
    Ok, thx for the confirmation. I didn’t success to make it work right now, but I will dig into it. Did you know anyone I could contact in case I’m stuck by using it ? Thank you again for your reply.
    • 1
    • 1
  • s

    Samuel Bichsel

    02/18/2021, 10:59 AM
    Hello, I just tried to update to Kotlin 1.4.30. Doing that breaks the iOS Builds with the following error:
    Execution failed for task ':shared:linkDebugFrameworkIosX64'.
    > Following dependencies exported in the debugFramework binary are not specified as API-dependencies of a corresponding source set:
      
      Project :dreimultiplatform
      
      Please add them in the API-dependencies and rerun the build.
    build.gradle:
    ios("ios") {
            binaries.withType(org.jetbrains.kotlin.gradle.plugin.mpp.Framework).all {
                transitiveExport = true
                export(project(":dreimultiplatform"))
            }
        }
    
        cocoapods {
            // Configure fields required by CocoaPods.
            summary = "Multiplatform Redux Sample"
            homepage = "<https://github.com/dreipol/multiplatform-redux-sample>"
            ios.deploymentTarget = "13.0"
            frameworkName = "ReduxSampleShared"
        }
    
        sourceSets["commonMain"].dependencies {
            api project(":dreimultiplatform")
    }
    Before it used to work. Does anyone had the same problem?
    p
    • 2
    • 7
  • a

    ak

    02/18/2021, 7:45 PM
    Hello, I am working on a KMP project that has a shared module along with an iOS and Android application. My iOS build is failing with the following result:
    Task :common:linkDebugFrameworkIOS FAILED
    e: Compilation failed: /default/linkdata/package_com.packagename
    
     * Source files: 
     * Compiler version info: Konan: 1.4.30 / Kotlin: 1.4.30
     * Output kind: FRAMEWORK
    
    e: java.nio.file.NotDirectoryException: /default/linkdata/package_com.packagename
    Is there a way for me to further debug this issue?
    s
    • 2
    • 2
  • d

    darkmoon_uk

    02/20/2021, 1:48 PM
    With Kotlin
    1.4.30
    and Android Studio Canary 7 (+ Gradle plugin
    alpha07
    ), I can no longer resolve iOS symbols. Have deleted
    .konan
    ,
    .gradle
    , `.idea`s and reset IDE caches, but still IDE shows red for any iOS SDK symbol. Compile is OK however! Any confirmation of this issue or ideas to resolve?
    l
    c
    k
    • 4
    • 4
  • g

    Gurupad Mamadapur [FH]

    02/20/2021, 7:04 PM
    Cross-posting to relevant channel - https://kotlinlang.slack.com/archives/C3PQML5NU/p1613734931154800
    • 1
    • 1
  • g

    Gurupad Mamadapur [FH]

    02/23/2021, 4:22 PM
    What is the best way to consume flowables from my shared module in ios to be used on SwiftUI views. Right now I am doing something like this -
    class AppState: ObservableObject {
    
        private var closeables = Array<Closeable>()
        private let viewmodel = AppViewModel()
        
        @Published private(set) var data:AppData? = nil
        
        init() {
            let close:Closeable = UtilsKt.watch(viewmodel.data) { any in. // watch is an extension function on flow that returns a closeable
                self.data = any as? AppData
            }
            
            closeables.append(close)
            
            viewmodel.load() // some api call
        }
        
        deinit {
            closeables.forEach { it in
                it.onClose()
            }
        }
        
    }
    Then use the object of AppState (ignore the naming) on SwiftUI view, marked with @ObservedObject. This is a bit tedious as I'll have to copy and mark (@published) for each exposed property from my shared viewmodel. Could directly use the viewmodel in a view but there is no lifecycle I know of where I can call close.
    l
    l
    r
    • 4
    • 23
  • a

    aleksey.tomin

    02/25/2021, 3:09 PM
    should i still be using this for usage Flow in swift code? https://github.com/JetBrains/kotlinconf-app/blob/master/common/src/mobileMain/kotlin/org/jetbrains/kotlinconf/FlowUtils.kt
    r
    l
    • 3
    • 2
  • d

    darkmoon_uk

    03/02/2021, 10:38 PM
    📱❤️ :kotlin: ❓ I very much want to return to using AppCode for iOS, which on our KMM project means forming the Xcode project in a way that makes the KMM plugin within AppCode properly aware of the shared Kotlin module. Maybe this integration is still considered Alpha - the return of the KMM plugin to AppCode seems really significant but the silence from JB is puzzling. I can see from setting up a new project in each new version of AppCode, that the project structure keeps changing in some way, which suggests they're less than confident in how this should ideally work at the moment. What I want to do is retrofit the latest approach to our current project; to make the AppCode Xcode project 'aware' of the KMM module. [JB] have you settled on the way this is supposed to work yet? We are currently using the Cocoapods plugin to build the Kotlin module as a 'Development Pod'. I can see that in the latest version, these three elements are at play: • The
    xcode-compat
    Gradle plugin • A distinct KotlinFramework target, which accomodates the familiar call-out to Gradle for building Kotlin/Native code • A check for the environment variable
    KOTLIN_NATIVE_BUILD_CAPABLE
    (who sets this?) Is there any documentation or guidance out there; anyone making this work?
    ➕ 1
    t
    a
    v
    • 4
    • 4
  • f

    Foso

    03/07/2021, 6:43 PM
    Hi, i'm trying to use XCTest from Kotlin but i cant figure out how to generate the bindings with cinterop. Can someone give me an example? I will post my (non-working) code in the thread.
    a
    • 2
    • 2
  • p

    Paul Woitaschek

    03/08/2021, 10:25 AM
    I'm planning to have some general programming educational sessions in our company. Therefore I would like our devs to prepare code snippets both in kotlin and in iOS so both platforms will be more familar with the other language that we're excessively using through kotlin native. The issue here is that most of our android devs are on linux. Is there a linux IDE for swift?
    t
    n
    • 3
    • 5
  • m

    Megan Teahan

    03/15/2021, 9:05 PM
    Hello all, I’ve been talking to my team about using KMP for our iOS development. The developers have concerns around the concurrency model for Kotlin/Native. I’ve read about Immutability and Concurrency on Kotlins website, along with an overview on the KMM site. Also watched some videos that explain and walk through this concept by Kevin Galligan:

    original talk▾

      and updated version. Kevin’s videos talk a lot about the concept and also ways to design with intention. It definitely seems like a trouble spot, but seems like issues are avoidable with intentional design with what is immutable vs mutable, Atomics in some cases, and potentially using the coroutines native-mt branch for multithreading. I was hoping to get others thoughts an opinions who use Kotlin for Native development. Has this been a non-starter for using Kotlin/Native for anyone who has looked into this topic or is something that’s workable? Or are there any other resources people recommend reading to better design for Native’s concurrency model?
    k
    • 2
    • 3
  • d

    darkmoon_uk

    03/17/2021, 7:15 AM
    Speaking of the above 👆 , I'm clearly missing another of the peculiarities of the K/N Memory Model... Getting the dreaded:
    Caused by: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@33944e8
    ...while adding an element to a
    MutableSet
    . However: • The Set is created while on the main thread • The Set is only ever accessed from the main thread (I've asserted these points with checks on
    NSThread.isMainThread
    at every relevant point) • The top level object under which the Set (indirectly) resides, is marked
    @ThreadLocal
    ...which other restriction am I missing!? Is there a way to determine at what point an object is being frozen?
    t
    r
    • 3
    • 8
  • w

    willyrs

    03/19/2021, 9:08 AM
    Is there a way to add swift code to the multiplatform project? I found a repo where there is a "swift" folder alongside the "kotlin" folder into "iosMain". I tried to do it but it seems that files get ignored. Could it be a custom gradle plugin? I'm referring to: https://github.com/icerockdev/moko-widgets/tree/master/widgets-collection/src/iosMain
    t
    a
    • 3
    • 7
  • t

    Tijl

    03/29/2021, 6:29 PM
    I’m currently dealing with some generic / nullability issues with ObjC/Swift/Kotlin interop. Below are three different ways of defining the generic type for a method and the generated header (irrelevant stuff stripped off)
    class Foo<T> { // no upper bound 
        fun bar(baz: (T) -> Unit) {
        }
    }
    
    @interface KNFFoo<T> : KNFBase // leads to T _Nullable as expected
    - (void)barBaz:(void (^)(T _Nullable))baz __attribute__((swift_name("bar(baz:)")));
    @end;
    
    class Foo<T:Any> { // Upper bound of Any
        fun bar(baz: (T) -> Unit) {
        }
    }
    
    @interface KNFFoo<T> : KNFBase
    - (void)barBaz:(void (^)(T))baz  // leads to T as expected __attribute__((swift_name("bar(baz:)")));
    @end;
    
    class Foo<T> {
        fun bar(baz: (T:Any) -> Unit) { // upperbound of Any just for the method
        }
    }
    
    @interface KNFFoo<T> : KNFBase
    - (void)barBaz:(void (^)(id))baz // <----- id not T? __attribute__((swift_name("bar(baz:)")));
    Anyone a little more familiar than me know if my assumption this could be T instead of id is correct?
    b
    k
    r
    • 4
    • 10
  • i

    Ivan Đorđević

    04/01/2021, 2:29 PM
    Hi, is it possible to combine exporting an umbrella framework (containing dependencies) with the CocoaPods plugin? https://kotlinlang.org/docs/mpp-build-native-binaries.html#export-dependencies-to-binaries Is there an example of this somewhere? Basically, is there a way to automate creating a .podspec file for such umbrella framework so that it can be integrated into iOS projects via CocoaPods?
    k
    • 2
    • 5
  • n

    Nikolay Kasyanov

    04/22/2021, 9:50 AM
    Hey folks, is it possible to adjust the iOS deployment target used by K/N to link binaries?
    • 1
    • 1
  • d

    darkmoon_uk

    04/28/2021, 4:18 AM
    This was supposed to have worked back here: https://blog.jetbrains.com/kotlin/2019/04/kotlinnative-support-for-appcode-2019-1/ ...but I think it since broke and has never worked again. Can't work out why this isn't a priority for AppCode team; being able to use AppCode on KMM projects would be a dream for the devs on my team. We'd definitely be buying licenses.
    👍 1
    t
    a
    • 3
    • 6
  • g

    Grzegorz Sagadyn

    04/29/2021, 5:41 PM
    Hi, Apple just released the new Xcode 12.5 that brings new Swift and so on but the new Xcode also brings the new requirement for libs that must be built with the APPLICATION_EXTENSION_API_ONLY set to true. So, when I try to build the app that consumes a KMP lib I get the following error:
    Application extensions and any libraries they link to must be built with the APPLICATION_EXTENSION_API_ONLY build setting set to YES
    Do you know any workaround for the above? Or do you have any schedule for a fix? I’m a little worried about it because I found that the mentioned flag is blacklisted (https://github.com/JetBrains/kotlin-native/blob/master/utilities/env_blacklist)
    👀 2
    b
    • 2
    • 3
  • a

    Anthony Pages

    05/04/2021, 2:01 PM
    Hi ! I'm having some dependencies issues with KMP and iOS Framework. I have the following architecture: 2 KMP modules: • KMPlibAPI: contains only interfaces • KMPlib: contains implementations and usages of KMPlibAPI When I build the KMPlib, the header include the KMPlibAPI definition. But I didn't wanted to be included in my KMPlib framework, I just wanted to have a needed references to KMPlibAPI. Exemple of what I have:
    //KMPlibAPI.h
    @protocol KMPAPIFoo
    @required
    - (void)bar __attribute__((swift_name("bar()")));
    @end;
    
    
    //KMPlib.h
    @protocol KAFoo  // <----- here we have a redefinition of the protocol.
    @required
    - (void)bar __attribute__((swift_name("bar()")));
    @end;
    
    @interface Baz
    - (void)injectFoo:(KAFoo)foo  __attribute__((swift_name("injectFoo(foo:)"))); // <----- and here we are using it, instead of using KMPAPIFoo
    @end;
    I've tried to put the dependencies in
    compileOnly
    into gradle, but nothing changed. Anyone is confortable with gradle compilation option for Kotlin native and dependencies ?
    l
    • 2
    • 14
Powered by Linen
Title
a

Anthony Pages

05/04/2021, 2:01 PM
Hi ! I'm having some dependencies issues with KMP and iOS Framework. I have the following architecture: 2 KMP modules: • KMPlibAPI: contains only interfaces • KMPlib: contains implementations and usages of KMPlibAPI When I build the KMPlib, the header include the KMPlibAPI definition. But I didn't wanted to be included in my KMPlib framework, I just wanted to have a needed references to KMPlibAPI. Exemple of what I have:
//KMPlibAPI.h
@protocol KMPAPIFoo
@required
- (void)bar __attribute__((swift_name("bar()")));
@end;


//KMPlib.h
@protocol KAFoo  // <----- here we have a redefinition of the protocol.
@required
- (void)bar __attribute__((swift_name("bar()")));
@end;

@interface Baz
- (void)injectFoo:(KAFoo)foo  __attribute__((swift_name("injectFoo(foo:)"))); // <----- and here we are using it, instead of using KMPAPIFoo
@end;
I've tried to put the dependencies in
compileOnly
into gradle, but nothing changed. Anyone is confortable with gradle compilation option for Kotlin native and dependencies ?
l

louiscad

05/04/2021, 5:21 PM
Hello,
compileOnly
isn't supported in Kotlin/Native. The solution is to set the visibility of implementation details to
internal
a

Anthony Pages

05/05/2021, 8:19 AM
Hello Louis, What do you mean by "set the visibility of implementation details to `internal`" ? The aim of splitting the API and the injection is to have the following behavior : 2 ios Project: • 1 swift package • 1 iOS app the swift package have the following implementation :
import KMPlibAPI

public class SampleFoo: NSObject, Foo {
   func bar() { } 
}
and into the app
import KMPlib
import MySwiftPackage

let foo = SampleFoo()

let baz = Baz()
baz.injectFoo(foo)
As you can see, I can't set
injectFoo
to
internal
here, otherwise I won't be able to call it through the iOS app. I'm not sure if I made it clear ?
l

louiscad

05/05/2021, 8:23 AM
Then don't make
injectFoo
internal, but make the rest
internal
?
a

Anthony Pages

05/05/2021, 8:24 AM
What do you call the rest ? the
baz
class ?
l

louiscad

05/05/2021, 8:25 AM
Whatever you don't want to expose to Swift.
a

Anthony Pages

05/05/2021, 8:27 AM
Yes but as soon as I expose
injectFoo(foo:Foo)
into the KMPlib, it will include the Foo protocol into the KMPlib.h and that's my point, I don't want to have the protocol exposed in the KMPlib.h but have a reference to the KMPlibAPI.h (which contain the
Foo
protocol)
l

louiscad

05/05/2021, 8:29 AM
I think what you want to do with what you have is simply impossible. Even in pure Kotlin, it's impossible to have a public declaration exposing an internal or private type.
a

Anthony Pages

05/05/2021, 8:30 AM
yes yes, none of them are private or internal, everything is public here
l

louiscad

05/05/2021, 8:32 AM
Then, that's it, right?
a

Anthony Pages

05/05/2021, 8:41 AM
Hmmm not really. In kotlin I can do what I wanted. For example:
// API project
public interface Foo

// libA project
public class Bar {
    fun doSomething(foo: Foo)
}

// libB project
import API

public class FooImpl: Foo { }

// android app
import libA
import libB

var foo = FooImpl()
var bar = Bar()
bar.doSomething(foo) // <----- Everything is fine here
but in iOS I can't:
// ios app
import libA
import libB

var foo = FooImpl()
var bar = Bar()
bar.doSomething(foo) // <----- Error here : FooImpl is of type APIFoo but here LibAAPIFoo is excpected
because I have the folowing headers :
/// API.h
@protocol APIFoo
// libA.h
@protocol LibAAPIFoo

@interface Bar
- (void)injectFoo:(LibAAPIFoo)foo
@end;
l

louiscad

05/05/2021, 8:49 AM
So much "foo", I have a really hard time wrapping my head around to be honest.
a

Anthony Pages

05/05/2021, 8:51 AM
Haha I understand, maybe I can host it on a github, it will probably be clearer.
l

louiscad

05/05/2021, 8:52 AM
I don't think I'll take the time, but I can tell you one thing: Swift protocols are not a 100% translation of interfaces in Kotlin (or Java), so that can explain some differences in the semantics. You might be able to work that around by using an abtract class with all abstract functions/properties.
a

Anthony Pages

05/05/2021, 8:56 AM
Ok, thank you for your time
View count: 6