https://kotlinlang.org logo
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
multiplatform
  • j

    Justin

    06/10/2022, 3:05 PM
    Has anyone made (or come across) any KMP iOS/Android libraries for dealing with the device camera (e.g. AVCaptureDevice on iOS, etc.)?
    l
    l
    • 3
    • 6
  • j

    Jonathan Ellis

    06/10/2022, 9:38 PM
    I have a project that I'm trying to update from jvm only to multiplatform (https://github.com/jbellis/delaunator). I took the basic multiplatform gradle build and added the maven-publish plugin. When I publish it locally, everything works. But when I try to consume it as a dependency from jitpack with a jvm-based client, I get an error that gradle couldn't find a jvm variant of the library (https://gist.github.com/jbellis/0d1cc53a64721f72b163a3b9152825e9). The jitpack pom is here https://jitpack.io/com/github/jbellis/delaunator/1.0.3.3/delaunator-1.0.3.3.pom and the build log is here https://jitpack.io/com/github/jbellis/delaunator/1.0.3.2/build.log. Nothing looks broken to me, but gradle is ignoring the -jvm artifact for some reason. Any ideas?
    b
    • 2
    • 2
  • m

    miqbaldc

    06/11/2022, 9:13 AM
    [SOLVED] Hi folks, recently we’re trying to integrate our codebase (Android & Kotlin module) to KMM But has problem when trying to sync it. We’re not sure if it the KMM side or the Android Plugin side, see error log in 🧵
    • 1
    • 2
  • a

    Adam Brown

    06/12/2022, 1:42 AM
    Anyone have a favorite KMP library for file Io?
    j
    a
    • 3
    • 6
  • n

    Nicolas Haan

    06/12/2022, 10:07 AM
    Hi All! I'm trying to add a dependency on this pod (https://github.com/apotocki/icu4c-iosx) aiming to use it through
    cinterop
    but I'm getting an error:
    > Task :cinteropIcu4c_iosxIosArm64 FAILED
    Exception in thread "main" java.lang.Error: /var/folders/z2/cmdsctqj089dsp264x9j5m3h0000gn/T/16980928468880910640.m:1:9: fatal error: module 'icu4c_iosx' not found
            at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:274)
            at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:75)
            at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
            at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:522)
            at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:285)
            at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLibSafe(main.kt:214)
            at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:80)
            at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
            at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:40)
            at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:62)
    Here is my
    build.gradle.kts
    along with a complete issue reproduction project: https://github.com/nicolashaan/cocoapods-error-repro/blob/main/build.gradle.kts I've seen that there are some issues with modules with a dash in the name: https://github.com/JetBrains/kotlin-native/issues/2884 I've tried a lot of things from specifying a
    moduleName
    for the pod to modify the podspec of the library with no luck. Do you have any idea of what can go wrong?
    j
    • 2
    • 2
  • s

    spierce7

    06/12/2022, 2:10 PM
    I’m trying to create a
    common
    API that is similar in Java and JS. It involves a tree of content, and each node is exposed through the common API. It’d be nice if I didn’t have to allocate an extra class for each node to properly delegate to each platform (since the trees can be rather large). Touchlab showed off an interesting approach a few years ago using expect / actual type aliases with extension properties. This doesn’t work in my case because some of the classes in JS aren’t open, or some are interfaces in Java, and classes in JS. I’m interested if there are any other creative solutions to this that I haven’t thought of.
    b
    • 2
    • 16
  • a

    Adam Brown

    06/13/2022, 2:35 AM
    Huh, adding
    kotlin("plugin.serialization") version "1.6.10"
    to my common module blows everything up, gradle starts complaining
    Caused by: org.gradle.internal.exceptions.DefaultMultiCauseException: Could not resolve all files for configuration ':common:desktopTestCompileClasspath'.
    • 1
    • 1
  • s

    Sebastian Sellmair [JB]

    06/13/2022, 11:19 AM
    Hey Folks 👋 Who would like to participate in the next multiplatform online meetup? :thread-please: Feel free to propose topics you would like us to talk about! :thread-please: Feel free to propose a virtual talk, if you have something you would like to present! Other than that, just join and ask questions ☺️ :virtual-meeting: Multiplatform Community Meeting 🕔 Monday, June 20 · 5:00 – 6:00pm CET/Munich Google Meet joining info Video call link: https://meet.google.com/avu-ijaj-joi Or dial: ‪(DE) +49 40 8081619507‬ PIN: ‪418 485 148‬# More phone numbers: https://tel.meet/avu-ijaj-joi?pin=8370633129540
    :plus1: 22
    ❤️ 8
    h
    o
    +5
    • 8
    • 33
  • j

    Joost Klitsie

    06/13/2022, 7:35 PM
    Hello! I have a KMP project in Android studio. At this point in time, I only have an android target. So I have a simple app module and a common kmp module. The app compiles, but highlighting and autocompletion is totally broken. Is there a known issue with android studio and KMP? Using kotlin 1.7.0, latest android studio chipmunk 2021.2.1 Patch 1
    m
    • 2
    • 8
  • c

    clark

    06/13/2022, 11:18 PM
    I just discovered this KMP wrapper around Firebase and it seems super awesome, but I'm not really sure I understand how to initialize it. Do you just follow normal, platform specific guides for Firebase App initialization or can you initialize in the common layer? Is there some documentation for this that I am missing? https://github.com/gitliveapp/firebase-kotlin-sdk
    r
    • 2
    • 3
  • b

    Big Chungus

    06/14/2022, 1:56 PM
    So what's the deal with
    androidMain
    and
    androidTest
    sourceSets? They seem to behave differently to other sourceSets somehow. For instance, injecting an intermediate sourceSet doesn't seem to work with this hierarchy:
    commonMain
      jsMain
      blockingMain
        androidMain
        jvmMain
        linuxX64Main
    I have an actual class in
    commonMain
    which I implement in
    jsMain
    and
    blockingMain
    . This works fine for all the targets EXCEPT android, which complains on compilation
    e: /path/File.kt: (11, 24): Expected class 'MyClass' has no actual declaration in module <my-module_release> for JVM
    I'm adding the dependecies like this
    kotlin {
      explicitApi()
      android {
        publishLibraryVariants("release", "debug")
      }
      sourceSets {
        afterEvaluate { // Crashes due to missing sourceSet if we don't do this in afterEvaluate
          named("androidMain") {
            dependsOn(getByName("blockingMain"))
          }
          named("androidTest") {
            dependsOn(getByName("blockingTest"))
          }
        }
      }
    }
    e
    s
    • 3
    • 9
  • s

    Sam

    06/14/2022, 3:38 PM
    Does anyone have any tips for mocking classes defined in Kotlin from Swift? Context being that I'm writing a Swift class that takes a Kotlin dependency. This works perfectly in production but in tests I'd like to be able to mock out that kotlin dependency
    m
    f
    g
    • 4
    • 13
  • m

    Marko Novakovic

    06/14/2022, 9:24 PM
    anyone else had this error?
    > Task :shared:compileKotlinIosSimulatorArm64
    
    > Task :shared:linkPodDebugFrameworkIosSimulatorArm64 FAILED
    e: Compilation failed: Expecting descriptor for kotlin.time/TimeMark.<init>|-5645683436151566731[0]
    
     * Source files: 
     * Compiler version info: Konan: 1.7.0 / Kotlin: 1.7.20
     * Output kind: STATIC_CACHE
    
    e: java.lang.IllegalStateException: Expecting descriptor for kotlin.time/TimeMark.<init>|-5645683436151566731[0]
    	at org.jetbrains.kotlin.backend.konan.serialization.KonanIrLinker$KonanCachedLibraryModuleDeserializer.deserializeIrSymbol(KonanIrlinker.kt:635)
    h
    • 2
    • 6
  • a

    andylamax

    06/15/2022, 1:11 PM
    Hi there, is there any known open source http client multiplatform library that doesn't use corountines under the hood??
    b
    e
    +3
    • 6
    • 26
  • l

    Landry Norris

    06/15/2022, 9:58 PM
    I noticed that androidx annotations is still an android-only library. With Compose and Datastore being experimentally KMM, is there any plan to move annotations over? This would help with models that I want to keep in commonMain, but may need annotations such as Keep (I need to access one model class via reflection in one project). Some, such as Discouraged, AnyThread, DoNotInline, ReturnThis, etc. may even be meaningful or useful in shared code.
    e
    k
    • 3
    • 11
  • y

    Yousef

    06/16/2022, 1:42 PM
    Hopefully this is the right channel to ask. Would the way to create a ktor-web-android multiplatform project be to create a fullstack app like this: https://play.kotlinlang.org/hands-on/Full%20Stack%20Web%20App%20with%20Kotlin%20Multiplatform/01_Introduction and then adding an android module?
    • 1
    • 1
  • s

    Sam

    06/16/2022, 1:52 PM
    Has anyone using KMM managed to import the shared module into the test target on iOS? (i.e. swift unit tests) I have a class called
    HelloWorld
    defined in Kotlin, works perfectly from the main swift code but trying to call it from the test target just fails with this
    • 1
    • 1
  • y

    Yousef

    06/16/2022, 4:28 PM
    i keep getting "The 'java' plugin has been applied, but it is not compatible with the Android plugins."
    e
    l
    s
    • 4
    • 15
  • a

    Alina Dolgikh [JB]

    06/17/2022, 11:21 AM
    📣 Hi! The survey is still ongoing – please share your feedback if you haven’t yet!
    👍 1
    d
    • 2
    • 1
  • t

    Tim Ortel

    06/17/2022, 2:31 PM
    Hi! For quite some time I have been working on a Gradle Plugin that brings GRPC to Kotlin Multiplatform. It currently supports JVM, Android and JS/Browser. It allows you to make grpc client-side calls from multiplatform code, as such allowing you to share your network logic across these platforms. I would greatly appreciate your feedback on the project! https://github.com/TimOrtel/GRPC-Kotlin-Multiplatform
    🙌 4
    🎉 2
    :nice: 6
    🙌🏾 1
    👀 3
    d
    • 2
    • 3
  • t

    tylerwilson

    06/17/2022, 4:50 PM
    Trying to build my shared module after adding macosArm64 target, into my universal XCFramework, and getting this:
    Fat frameworks are not supported for platform
    macos_arm64
    Is this true, or is my configuration messed up?
    h
    b
    • 3
    • 3
  • r

    Rachel Carandang

    06/17/2022, 10:41 PM
    Has anyone been able to successfully get a KMM library running on a arm64 simulator on an M1? I posted by build.gradle earlier, but after working through several related errors, I keep getting errors in Xcode when building. If anyone could post their build.gradle/link to their project setup or give suggestions that would be helpful. https://kotlinlang.slack.com/archives/C3PQML5NU/p1654122829530829
    h
    k
    m
    • 4
    • 8
  • a

    Ali Khaleqi Yekta

    06/18/2022, 11:59 AM
    Hi I've been struggling to fix a bug for the last 2 weeks. In a KMP project with a modular architecture, module
    B
    depends on module
    A
    . Module
    A
    has some code inside its
    commonMain
    that module
    B
    can access, because it depends on
    A
    . The thing is, the code inside module
    A
    can be accessed by any
    sourceSet
    of module
    B
    , EXCEPT from
    androidMain
    !!! I can even access the code written in
    A
    from `B`'s
    jvmMain
    , but not
    androidMain
    . When I try to do so, Android Studio (The latest stable version), says:
    Unresolved reference: {NameOfTheClass}
    ---
    Add dependency on module '{NameOfMyProject}.A.commonMain'
    I don't exactly know when the problem has occurred, but I guess it was after updating the version of some dependencies (especially kotlin 1.6.10 to 1.6.21). I tried changing the versions again and cleaning the project every time; I tried invalidating the caches, I even migrated from a Linux based system to Windows; nothing worked. Some of the current versions:
    Android build tools: 33.0.0
    app compat: 1.4.2
    Kotlin: 1.6.21
    coroutines: 1.6.2
    Kotlinx Datetime: 0.3.2
    Kotlinx Serialization: 1.3.3
    core ktx: 1.8.0
    activity compose: 1.5.0-rc01
    coil: 2.1.0
    koin: 3.2.0
    jvm targets: 11
    compose: 1.1.1
    Android gradle: 7.2.1
    Kotest: 5.3.0
    moko resources: 0.20.1
    ktor: 2.0.2
    ...
    UPDATE: When I downgraded android gradle to 7.1.3, the app successfully compiles and I can run it inside the emulator. However, the IDE still shows the Unresolved dependency error, even though it compiles! How to fix this? UPDATE: Downgrading the android gradle plugin to
    7.1.3
    and adding:
    kotlin.mpp.hieraricalStructureSupport=false
    solved the issue, BUT, made the jb compose not work in `commonMain`s.
    e
    • 2
    • 6
  • a

    Ali Khaleqi Yekta

    06/18/2022, 12:54 PM
    My previous issue made me wonder what exactly
    kotlin.mpp.hieraricalStructureSupport
    is, why is it now enabled by default, and what will I lose if I turn it off? I couldn't get a clear answer reading the description from kotlinlang.org.
    e
    • 2
    • 2
  • j

    Javier

    06/19/2022, 10:45 AM
    I am trying to find a youtrack issue which talks about the issue of consuming a KMP from maven instead of Gradle which forces to use
    -jvm
    without a workaround. But I can't find it, anyone has it at a hand?
    e
    a
    • 3
    • 3
  • a

    Andrew

    06/20/2022, 4:33 AM
    Is it possible to have a dependency on a KMP project (just the java part obviously) in a non-kmp project? Just trying to do this I get an error "could not resolve :myKmpProject", and most of the documentation shows the declaration to be done nested somewhere in the kotlin {} block of the gradle file which a simple java project doesn't have.
    dependencies {
        ...
        implementation project(':myKmpProject')
    }
    a
    • 2
    • 2
  • t

    Tlaster

    06/20/2022, 6:05 AM
    When I publish a library it seems that I can not use the library code in commonMain, but the library is written in commonMain, does anyone have the same issue?
    a
    e
    • 3
    • 6
  • t

    timkranen

    06/20/2022, 12:07 PM
    Hi all. Small question, does anyone recognize this issue? I’m integrating an existing iOS project into an Android one. The shared kmm module lives inside that same Android project. I’m integrating the iOS project using a git submodule. When I try to build the project however, the following command fails:
    Showing All Messages
                    "$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework                     -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME                     -Pkotlin.native.cocoapods.archs="$ARCHS"                     -Pkotlin.native.cocoapods.configuration="$CONFIGURATION"
    due to: Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain I can’t seem to modify the script in the .pubspec to echo the location of $REPO_ROOT, but when I try to run this command from the root of the iOS project it does work. Is there a way to modify the relative path used in the .pubspec to call the gradle task? Seeing how the pubspec file is generated I’m not sure how to go about this.. Not even sure why it’s not working, it could be because I’m using a symlink in the Podfile to link to the shared kmm module?
    • 1
    • 1
  • m

    Mohammed Babelly

    06/20/2022, 12:43 PM
    Hey there, how can I build
    .ipa
    app of my kmm ios app?
  • a

    Anton Afanasev

    06/20/2022, 1:23 PM
    I remember kmm used to have some restrictions having default arguments and swift/objective-c. Is it still a case? Recently I tried that out and it seem that kotlin native compiler does respsect function with default argument. So this:
    fun sendMessage(text: String, customAttributes: Map<String, String> = emptyMap())
    translated to this:
    func sendMessage(text: String, customAttributes: [String : String] = [:])
    Am I seeing write? kotlin 1.6.10
    k
    r
    • 3
    • 8
Powered by Linen
Title
a

Anton Afanasev

06/20/2022, 1:23 PM
I remember kmm used to have some restrictions having default arguments and swift/objective-c. Is it still a case? Recently I tried that out and it seem that kotlin native compiler does respsect function with default argument. So this:
fun sendMessage(text: String, customAttributes: Map<String, String> = emptyMap())
translated to this:
func sendMessage(text: String, customAttributes: [String : String] = [:])
Am I seeing write? kotlin 1.6.10
k

kpgalligan

06/20/2022, 2:44 PM
func sendMessage(text: String, customAttributes: [String : String] = [:])
That’s swift. The Kotlin compiler would be generating objc. Where do you see that? Default parameters aren’t available, unless something I’m not aware of happened.
a

Anton Afanasev

06/20/2022, 3:01 PM
That is really odd. I would expect to see Kotlin compiler generating obj-c as well. Instead, I am seeing a swift generated code... I see that by using the regular XCode
Jump To Definition
tool. Thats weird...
Interestingly, if I pass an empty map as a default argument swift would not force me to provide a value for this argument. So I can do something like that: common:
fun sendMessage(text: String, customAttributes: Map<String, String> = emptyMap())
ios/swift
client.sendMessage(text: "Hello")
No warnings or errors. But that only work with emptyMap. If I go and define some other default argument, lets say:
fun sendMessage(text: String, customAttributes: Map<String, String> = mapOf("a" to "b")
They default argument will be ignored and the value of
customAttributes
in that case will be empty map as well. Is it possible that K\N compiler always treat a map argument as an emptyMap, unless actual value is provided?
r

Rick Clephas

06/20/2022, 4:08 PM
Cool! Didn’t know about this. This is actually part of the Swift - ObjC interop:
An argument whose Objective-C type is an NSDictionary defaults to nil if the NSDictionary is nullable and [:] if the NSDictionary is non-nullable, under the following conditions:
• the argument label contains the word “options” or “attributes”, or the two words “user info” one after another
• the argument label is empty and the method base name ends with the word “options” or “attributes”, or the two words “user info” one after another
https://github.com/apple/swift/blob/main/docs/CToSwiftNameTranslation.md#default-argument-values
😳 1
👍 1
Another nice one is:
A final argument that is a nullable function or block pointer defaults to nil.
fun doSomething(block: (() -> Unit)?) = TODO()
can be called from Swift like:
doSomething() // default nil
doSomething { }
k

kpgalligan

06/20/2022, 4:34 PM
Huh, interesting
I didn’t know that either
a

Anton Afanasev

06/20/2022, 5:57 PM
Thanks @Rick Clephas and @kpgalligan Thats a nice thing to know. Sounds like some sort of
easter egg
View count: 32