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
  • m

    MarkRS

    01/05/2022, 10:50 AM
    How do I work with pointers to ios types? I want to access CGPath, but Android Studio only seems to present me with CPointer<CGPath> and doesn't help me much past there, and I haven't found anything on the web to show me how to work with that in Kotlin. I figured "apply" would go in the right direction and then "it" would be a CGPath object. Is that right? If so, what then?
    s
    • 2
    • 20
  • b

    Brian Guertin

    01/06/2022, 6:04 PM
    One of my devs is getting this error, anyone have any idea why? We're all using same Xcode version (13.2.1):
    > Task :jgosdk:linkReleaseFrameworkIosArm64 FAILED
    The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
    output:
    ld: library not found for -lSystem
    FAILURE: Build failed with an exception.
    • 1
    • 1
  • a

    Akash

    01/07/2022, 6:13 PM
    Hello Tech Geeks, I’m getting an error with my iOS framework while using on M1-chip mac. “Could not find module ‘KycSDK’ for target ‘arm64-apple-ios-simulator’; found:x86_64-apple-ios-simulator, x86_64,”
    p
    s
    s
    • 4
    • 17
  • a

    Akash

    01/07/2022, 6:13 PM
    Can anyone please help on this?
    k
    s
    • 3
    • 2
  • x

    xxfast

    01/18/2022, 9:53 AM
    Hi all. Having issues building my ios project with release configuration. It seems to fail when building the kotlin multiplatform library with
    Execution failed for task ':app:linkReleaseFrameworkIosX64'.
    > Task :login:linkReleaseFrameworkIosX64 FAILED
    e: Compilation failed: null
    
     * Source files: 
     * Compiler version info: Konan: 1.6.10 / Kotlin: 1.6.10
     * Output kind: FRAMEWORK
    
    e: java.lang.NullPointerException
    	at org.jetbrains.kotlin.backend.konan.optimizations.DataFlowIR$SymbolTable.mapClassReferenceType(DataFlowIR.kt:520)
    With very little to go on. Should note that it builds successfully for
    Debug
    . Anyone encountered this before? full :wood: in the 🧵
    a
    • 2
    • 6
  • b

    Brian Guertin

    01/18/2022, 11:06 PM
    Anyone know why
    kotlin.collections.HashMap.get
    would be causing
    EXC_BAD_ACCESS
    on iOS? It only happens sometimes
    d
    • 2
    • 4
  • b

    Brian Guertin

    01/19/2022, 4:10 AM
    I figured it out... apparently, kotlinx.serialization was hitting the iOS stack size limit (1mb), and increasing the stack size (via linker flags:
    -Wl,-stack_size,0x800000
    ) solved the issue. Sharing in case anyone else has
    EXC_BAD_ACCESS
    issues.
    👏 2
    n
    l
    • 3
    • 4
  • s

    Slavi

    01/19/2022, 1:51 PM
    Are there any recently updated examples about how to use coroutines from kmm module in swift ? I'm struggling to find any I'm receiving runtime crash with mutated frozen objects and have no idea how to debug this and where something went wrong. Without various wrappers that I managed to find I stumbled upon "NSLocalizedDescription" : "There is no event loop. Use runBlocking { ... } to start one." which I don't understand how to fix as well. Will switching dependencies manually to "-native-mt" really help (as old answers on stackoverflow suggest)?
    ➕ 1
    • 1
    • 1
  • g

    Gonçalo Frade

    01/24/2022, 9:59 AM
    Hello there everyone. Im quite new to KMM and I have a issue was wondering if I can get your help. I have some native code on Kotlin and I wanted to create a Static Library from it, an objective-C static library. I maybe wrong but it seems the Static Library created by KMM is a C++. Wonder if I can create a Objective-C static library with the .swiftmodules?
    z
    • 2
    • 3
  • p

    Philipp Bykow

    01/25/2022, 2:36 PM
    Hello all. We have a KMM project and try to run the App on iOS but when executing the following error comes
    Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
    and crashes the App. In the class init we call something like this
    coroutineScope.launch {
        test()
    }
    The test function is as followed:
    @Throws(Exception::class)
        private suspend fun test() {
           ...
        }
    k
    • 2
    • 5
  • m

    MarkRS

    01/26/2022, 1:07 PM
    I've just updated AS to Bumble Bee and my Mac installation is now complaining that CocoaPods isn't installed. It is, and it's the latest version (1.11.2), as is cocoapods-generate. I've restarted, cleared caches, and sacrficed half a dozen virgins but it still won't work. Any suggestions?
    v
    l
    • 3
    • 10
  • m

    michaelv

    01/28/2022, 6:10 AM
    Normally when I write tests I test against the interface rather than the implementation. However in Swift because of the PAT’s it seems I can’t do that now? Is it true? I can only test against the implementation now? What is the best practice here?
    s
    • 2
    • 3
  • m

    michaelv

    01/31/2022, 6:33 AM
    did anyone try to use async/await as described here by John O’Reilly and get it to work in unit tests? I could get it to work as described by calling with
    async { <viewModel function to run> }
    from the view, but from the unit tests it doesn’t do anything using this
    async {}
    syntax since it doesn’t wait for it. It seems that it’s not normal to call it like that in unit tests and just call it with
    try await
    only. However if I do that I get the IncorrectDereferenceException. I’m not sure if it’s currently possible to do it or if I just wasn’t doing it right. I’m not using the new memory model but maybe that would work. It’s not a big deal as I have it working without async/await but I really like the async/await syntax and eventually want to move to it. https://johnoreilly.dev/posts/swift_async_await_kotlin_coroutines/
    s
    n
    • 3
    • 3
  • n

    nhaarman

    02/02/2022, 4:07 PM
    I've got an immutable data class that I'm sharing with swift. When I'm creating an instance of that class and access it from another thread I get the 'illegal attempt to access non-shared object' error. How can I share this instance between threads in swift?
    k
    • 2
    • 8
  • s

    Stefan Oltmann

    02/03/2022, 2:04 PM
    Forgive me this iOS only question, but I really don't find the correct solution. 🙈 How can I make that my SwiftUI task runs on the background?
    task
    is always on the main thread.
    Task.detached
    starts a new task on another thread. The problem is
    Task.detached()
    runs to completion even is task is cancelled because the cancellation is not propagated. Can some expert please enlight me how to correctly do that?
    .task {
    
          Task.detached {
    
            guard image == nil else { return }
    
            image = await imageLoader.loadThumbnailImage(photoUri: photo.uri)
          }
        }
    ✅ 1
    h
    • 2
    • 19
  • b

    Brian Guertin

    02/10/2022, 8:30 PM
    When I declare a list taking nullable items in Kotlin:
    fun myFunc(list: List<*>?): List<*>
    // OR
    fun myFunc(list: List<Any?>?): List<Any?>
    The iOS (Swift) definition is
    func myList(list: [Any]?) -> [Any]
    (not nullable items). Is this a known issue? Any workaround?
    n
    s
    • 3
    • 4
  • m

    MarkRS

    02/14/2022, 11:44 AM
    Is there some problem with manipulating objective-c classes from Kotlin? I'm sure the answer should be "no", but I'm getting nowhere with creating and manipulating CGMutablePaths. The code doesn't throw errors, I can watch it run in the (XCode) debugger, but the paths never seem to acquire any elements. The variable window shows my CGmutablePath variable as "(void **)". which is worrying, but below that shows it as "(__NSCFType *)", and both with "Summary Unavailable". However, both show memory locations as if something has been allocated... Any ideas?
    s
    • 2
    • 5
  • j

    julien hamon

    03/09/2022, 6:25 AM
    Hi everybody i need your help to know how i could to see an entity in the kotlin shared module (iOSMain). For details i have a pods with his own entities (API and custom iOS pods) that i use with the expect/actual pattern. All work fine but i don’t arrive to see the attributes of my entity. exemple :
    @objc public class CourseImpl: NSObject, Decodable, Course {
        let objectID: String
        let status: Bool
    
        @objc init(objectID: String,
             status: Bool,
             title: String
        ) {
            self.objectID = objectID
            self.status = status
            self.title = title
           
        }
    in iosMain
    actual fun search(words: String): List<Training> {
            val client = SearchClient()
            client.initializeWithAppId("", apiKey = "")
            client.searchWithText(text = words , indexName = "", callback = { response: List<Course> ->
                response.map { it.objectID // don't work }
    
            }.freeze() as (List<*>?) -> Unit)
            return listOf(Training(id = "1", name = "name1"), Training(id = "2", name = "name2"))
        }
    could you help me to undestand ? thanks
    s
    • 2
    • 5
  • b

    brabo-hi

    03/11/2022, 4:06 AM
    Hi all what is the best way to consume kotlin flow in swift
    x
    j
    r
    • 4
    • 8
  • m

    MarkRS

    03/16/2022, 12:46 PM
    Coming from an initially Android project, how to build language localisation into the iOS version when strings are called from common code? I know there are libraries for that, I'm wondering more about building it myself, it's (perhaps) not hard. It's easy to build a resource manager to dispense strings, but my main blocker is that, in contrast to Android, iOS seems to key strings from a main language version and I'm not sure how to square that with the "string name" strategy taken by Android
    r
    g
    • 3
    • 3
  • u

    ursus

    03/20/2022, 1:09 PM
    Hi, im a android senior but would like to dabble in ios. Could someone point me on the libraries? Hey, I’m trying to get a working knowledge of ios/swift (to get kmp going) Does someone here know what’s the state of the art for ios in terms of libraries? 1. What’s the go to persistance library? (is sqlite popular as well?) 2. What’s the go to networking library? 3. What’s the go to DI library? 4. What’s the go to reactive framework? (I read there is frst party Combine?) 5. What’s the status of async-await? Does it play nice with Combine as suspend functions do with kotlin Flow? 6. Should I still bother to learn UIKit when swift ui exists? Is it not prod ready? 7. What package manager?
    a
    m
    • 3
    • 4
  • u

    ursus

    03/20/2022, 10:19 PM
    Btw any AppCode users here? Why is SPM grayed out?
    n
    • 2
    • 2
  • v

    Vivek Modi

    04/14/2022, 11:14 PM
    Hey guys how can I get application version code in iosMain in KMM ? I asked my ios team they provide me some code which is working in iOS side
    let appVersion = “iOS ” + (Bundle.main.versionNumber ?? “”)
    But I don't understand how to use this in iosMain in kmm. Is any other code ?
    r
    h
    • 3
    • 3
  • r

    ribesg

    04/20/2022, 8:21 AM
    The new memory model is cool but
    BUILD SUCCESSFUL in 24m 37s
    56 actionable tasks: 47 executed, 9 up-to-date
    18:31:05: Execution finished 'build'.
    🥶 1
    👀 1
    d
    • 2
    • 8
  • b

    bod

    04/28/2022, 9:33 AM
    Hello, World! I'm trying to find
    NSURLSessionTask.delegate
    (this) in Kotlin, but I'm not seeing it. I'm suspecting it may be because it's a recent API that's not yet in Kotlin? (related: wondering how this works actually, does Kotlin keep up with new Apple APIs? Is there a doc with the current version of the APIs that is supports?)
    r
    l
    • 3
    • 5
  • m

    Marek Niedbach

    05/02/2022, 9:15 AM
    Hi there 👋 Is it possible that Apple’s
    CryptoKit
    will be available in the future as a platform library in the kotlin native ios? Currently there is only
    CoreCrypto
    available which doesn’t have the features I need…
    t
    • 2
    • 3
  • m

    Matthew Kruk

    05/02/2022, 8:34 PM
    I'm writing a library with a UIViewController that I would like to present as fullscreen, but am so far unsuccessful. I'm calling
    viewContoller.presentViewContoller(this, animated = true, completion = null)
    but it presents as a modal just the same as calling
    viewController?.presentModalViewController(this, animated = true)
    . I've also tried explicitly calling
    viewController?.setModalPresentationStyle(UIModalPresentationFullScreen)
    with the latter. Any idea what I'm doing wrong?
    n
    r
    • 3
    • 2
  • j

    James Black

    05/03/2022, 10:14 PM
    I am using and I am trying to match iOS async/await with coroutines.
    Cannot pass function of type '() async -> Void' to parameter expecting synchronous function type
    This is the call in iosMain:
    actual suspend fun retrieveCurrentForecastByCity(city: String): MonthlyForecast? {
        return weatherRepository.retrieveCurrentForecastByCity(city)
    }
    This code is the action inside a button, but keeping it simple:
    await outfitViewModel.currentWeather(city: city)
    let a = outfitViewModel.currentWeatherFlow
    I can share the repo, but it doesn't compile right now, but basically I call currentWeather, which is a 'suspend' and everything from there is suspend functions. In Android I can use runBlocking { } and and works. I am using pod 'KMPNativeCoroutinesAsync', '0.12.2' and targeting iOS 15. Missed one variable. This all works fine on the Android side and everything after this call is in my shared project.
    var currentWeatherFlow = MutableSharedFlow<MainTemperature>(1)
    r
    • 2
    • 4
  • v

    Vivek Modi

    05/04/2022, 2:28 PM
    Hey guys I need help in ios code. I have
    class KtorCountryApi : NetworkRoute(), KoinComponent {
    
        private val httpClient by inject<HttpClient>()
    
        suspend fun getCountry(): ApiResponse<KtorCountriesResponse> {
            val response = httpClient.get {
                url("xyz")
            }
            return apiCall(response)
        }
    }
    NetworkRoute
    open class NetworkRoute {
        suspend inline fun <reified T : Any> apiCall(httpResponse: HttpResponse): ApiResponse<T> {
            return try {
                ApiResponse.Success(httpResponse.body())
            } catch (e: Exception) {
                ApiResponse.Error()
            }
        }
    }
    when I am calling in ios code
    let ktorApi = KtorCountryApi()
        ktorApi.getCountry()
    I am getting weird issue
    'async' call in a function that does not support concurrency
    r
    • 2
    • 3
  • v

    Vivek Modi

    05/05/2022, 2:03 PM
    Hey guys, I am trying to use interface in swift, but it unable to find the property
    commainMain
    interface ApplicationToken {
        val accessToken: String
        val refreshToken: String
    }
    iosMain
    Platform.kt
    lateinit var tokenProvider: ApplicationToken
    HttpClient.kt
    actual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = HttpClient(Darwin) {
        config(this)
        engine {
            configureRequest {
                setAllowsCellularAccess(true)
            }
        }
        install(Auth) {
            bearer {
                loadTokens {
                    BearerTokens(tokenProvider.accessToken, "")
                }
            }
        }
    }
    Now when I am to access
    tokenProvider
    in my swift code. It cannot find. I am adding image please have a look.
    l
    • 2
    • 3
Powered by Linen
Title
v

Vivek Modi

05/05/2022, 2:03 PM
Hey guys, I am trying to use interface in swift, but it unable to find the property
commainMain
interface ApplicationToken {
    val accessToken: String
    val refreshToken: String
}
iosMain
Platform.kt
lateinit var tokenProvider: ApplicationToken
HttpClient.kt
actual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = HttpClient(Darwin) {
    config(this)
    engine {
        configureRequest {
            setAllowsCellularAccess(true)
        }
    }
    install(Auth) {
        bearer {
            loadTokens {
                BearerTokens(tokenProvider.accessToken, "")
            }
        }
    }
}
Now when I am to access
tokenProvider
in my swift code. It cannot find. I am adding image please have a look.
l

Landry Norris

05/05/2022, 6:36 PM
Swift doesn't have global variables and functions. Kotlin translates them to static on a class called {filename}Kt, so for example, var bar in Foo.kt translates to FooKt.bar in swift
v

Vivek Modi

05/05/2022, 7:54 PM
Sure thanks a lot
View count: 5