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
ios
  • s

    Sean Keane

    01/16/2020, 7:22 PM
    Hi everyone! We are building a networking layer to be shared across Android and iOS and in the future Web. The issue I'm facing at the moment is the common.framework (Common is my shared module name) size is 12mb? but when it compiles the android aar file its ~200kb. We look to expose these SDK's to clients. Is it possible to reduce the size of the framework that has been generated?
    d
    • 2
    • 1
  • a

    asarazan

    01/16/2020, 8:02 PM
    Also how does your network stack differ from, say ktor, which already provides a large set of network functionality in common kotlin?
    s
    • 2
    • 1
  • g

    GarouDan

    01/18/2020, 9:56 PM
    Hi, I’m trying to generate frameworks for my project but I’m not being to deploy because the output is incorrect Does someone know how can I configure the
    xcode
    block from the
    kotlin("xcode-compat")
    plugin in order to achieve that? For example, with this
    xcode {
        setupFramework("KotlinNativeFramework")
    }
    a directory called KotlinNativeFramework will be created inside of the build folder, but the actual frameworks inside of this folder (
    *.framework
    ,
    *.framework.dSYM
    ) have a much longer name and also their inner definitions will be pointing to this other name. It looks like tha name come from the linkTask but I don’t know how to change the output definitions, does someone know?
    • 1
    • 1
  • t

    Trond Tunheim

    01/22/2020, 1:32 PM
    Hi everyone , I'm developing an app for IOS in Kotlin-native in Appcode. I'm wondering if anyone else have come across the following issue in Appcode. The error (no signature found) comes up if I try to redeploy an app to my iPhone without changing the code. If I change something in the code it deploys fine.
    a
    r
    • 3
    • 3
  • f

    fcosta

    01/23/2020, 4:42 PM
    Hi! Any idea how can I run ios tests in my common module with cocoapoads from xcode?
    b
    k
    • 3
    • 14
  • d

    darkmoon_uk

    01/26/2020, 1:05 AM
    Any for improving the iOS linking stage of Kotlin/Native? For some reason this seems to be a very slow process - much slower than ObjC/Swift equivalent - is there a sound reason for this or it's just very unoptimised from the Kotlin/Native side?
    s
    o
    • 3
    • 2
  • h

    Henrik

    01/28/2020, 9:32 AM
    I am having trouble calling certain iOS functions from Kotlin/Native How would I for example call this method? https://developer.apple.com/documentation/foundation/nsstring/1407654-write I have tried using variations like this, but it does not seem to compile no matter what I try:
    val contents = "File contents"
    val filename = "some.file"
    val res = contents.writeToFile(filename, true, NSUTF8StringEncoding)
    I have succeeded using the simpler overload without encoding end error, but the
    NSError*/throws
    is causing me problems. How can I supply/catch that parameter from Kotlin?
    a
    • 2
    • 4
  • r

    Romain Dubreucq

    01/31/2020, 11:08 AM
    Hello! I have two questions on Cocoapods plugin: 1. Does the Cocoapods plugin handle remote repositories? Most of the examples I have found only show an integration where the iOS app is part of the K/N project 2. Is there a parameter to tell the plugin that the generated podspec should be at the root directory? For the moment, my multiplatform project is organized with a root project and a submodule (with a build.gradle file in each)
    a
    • 2
    • 4
  • h

    Henrik

    02/04/2020, 8:04 AM
    I have problems getting XCode to choose the correct platform (Amr64/X64) for my Kotlin Native library. Following some different guides, I have done this: 1. Added my framework as embedded library. Here I choose either the X64 or Arm64 "debugFramework" folder, since there is no "general" headers generated 2. Added two different framework search paths, one for "Any iOS Simulator" and one for "Any iOS SDK", pointing to X64 or Arm64 respectively It seems no matter what I do, it will build and launch using whatever architecture I set in #1, regardless if I run on the simulator or a real device, and ignore #2, so I need to re-add the entire framework in Xcode when switching between simulator and device. Suggestions?
    r
    b
    • 3
    • 13
  • t

    Trond Tunheim

    02/04/2020, 12:01 PM
    Hello ! I'm trying to load an image from Assets.xcassets into UIImage
    val image = UIImage("mypin")
    The file mypin.png is copied into Assets.xcassets in Xcode . This doesn't work , it fails to load the image. Anyone that has any thoughts on how to do this correctly?
    r
    r
    • 3
    • 7
  • h

    Henrik

    02/07/2020, 1:29 PM
    KotlinByteArray to/from NSData in iOS? I have been struggling for hours trying to make my MPP code with with iOS regarding to NSData, and no examples I have found seems to work. I have a Kotlin function that takes a ByteArray as input, and another producing a ByteArray as output. This works perfectly in Java, mapping to byte[], but I have no idea how in iOS I can convert it to/from NSData that can be used in Swift. Any ideas?
    a
    • 2
    • 6
  • r

    ribesg

    02/07/2020, 4:02 PM
    Any idea how I could work around the fact you can’t override
    UIView.draw
    ?
    l
    • 2
    • 10
  • s

    Samuel Michael

    02/09/2020, 10:20 PM
    Hi can’t get this multiplatform ios to run I heard people say run gradle wrapper but that doesn’t seem to help is there any other way I really wanna get this running already spend all weekend its kind of pointless to do Multiplatform mobile with only android
    b
    a
    j
    • 4
    • 26
  • s

    Samuel Michael

    02/10/2020, 7:26 AM
    Also having trouble with the KaMP starter can’t get the kotlin plugin to work tried rolling back to 1.3.61 and nothing seems to work
    l
    r
    • 3
    • 5
  • r

    ribesg

    02/10/2020, 2:43 PM
    Still no good way to convert a
    NSError
    into a
    Throwable
    ?
    l
    • 2
    • 1
  • n

    Nikolay Kasyanov

    02/11/2020, 11:05 AM
    hey, I’m curious if someone has solved the problem of publishing iOS frameworks as Maven artifacts (to Artifactory, for example). I know it’s not officially supported (yet?), are there good solutions out there? So far I’ve been able to find this: https://github.com/SalomonBrys/kotlin-ios-universal-framework. Related question: does anyone know why Kotlin’s CocoaPods plugin is hardcoded to use static frameworks only? (https://github.com/JetBrains/kotlin/blob/0fe5694cb761e9de55ea76062a258b99677adaea/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt#L75)
    p
    • 2
    • 1
  • s

    Sam

    02/13/2020, 7:47 PM
    are these target platform/device enough for all of models ( > iphone 5s)?
    j
    s
    • 3
    • 4
  • r

    Romain Dubreucq

    03/02/2020, 4:45 PM
    Hello there! Did someone succeed to publish a Kotlin Native library on GitHub with the Cocoapods plugin?
    y
    • 2
    • 5
  • g

    gonzooin

    03/10/2020, 12:50 PM
    Hello. I’m trying to prevent rotation of a specific uiviewcontroller and i’m not able to override
    supportedInterfaceOrientations
    Anyone know how to achieve this ?
    s
    • 2
    • 4
  • d

    dazza5000

    03/12/2020, 2:39 PM
    Does anyone have a todo list multiplatform example or something similar that is on both android/ios?
    s
    r
    • 3
    • 3
  • c

    Christian Sousa

    03/12/2020, 3:34 PM
    Hey there, I’m using kotlin to create a function that returns a view, but I’m having issues finding documentation about creating elements using the UIKit, for example, I already have buttons and labels, but I have no idea on how to add an image.. someone can point me in the right direction?
    s
    • 2
    • 4
  • c

    Christian Sousa

    03/13/2020, 2:19 PM
    Anyone has an example of a “page” being created with content (UIView, UIImageView, etc.) on Kotlin? My goal is to have a function that returns a complete page, but I’m having a hard time figuring out how to place everything correctly
    r
    s
    • 3
    • 4
  • c

    Christian Sousa

    03/16/2020, 3:05 PM
    Sorry for bothering everyone, does anyone have an example using a UIPickerView? Thank you in advance 🙂
    s
    • 2
    • 1
  • c

    Christian Sousa

    03/17/2020, 12:23 PM
    I’m trying to subclass UITextField, but I get this error:
    Unable to call non-designated initializer as super constructor
    . The code I have is:
    private class Select: UITextField {
    
        @OverrideInit
        constructor(): super()
    
        override fun caretRectForPosition(position: UITextPosition): CValue<CGRect> {
            return CGRectMake(x = 0.0, y = 0.0, width = 0.0, height = 0.0)
        }
    
        override fun selectionRectsForRange(range: UITextRange): List<*> {
            return listOf<Any?>(null)
        }
    
        override fun canPerformAction(action: COpaquePointer?, withSender: Any?): Boolean {
            return false
        }
    }
    Anyone know what should I do? I guess I could use
    disableDesignatedInitializerChecks
    but that doesn’t seem right
    n
    r
    • 3
    • 5
  • p

    phldavies

    03/19/2020, 11:29 AM
    When implementing an ObcJ protocol, how can you work around conflicting overloads? For example, implementing
    override fun locationManager(manager: CLLocationManager, didEnterRegion: CLRegion) 
    override fun locationManager(manager: CLLocationManager, didExitRegion: CLRegion)
    override fun locationManager(manager: CLLocationManager, didStartMonitoringForRegion: CLRegion)
    r
    t
    l
    • 4
    • 13
  • c

    Christian Sousa

    03/25/2020, 6:24 PM
    Hello all, trying to create a UIView with rounded corners and shadows, after digging through some code online I ended up with something like this:
    private fun generateViewWithShadow(): UIView {
            var generatedView = UIView().apply {
                translatesAutoresizingMaskIntoConstraints = false
                heightAnchor.constraintEqualToConstant(60.0).active = true
            }
    
            var size = CGSizeMake(20.0, 20.0)
            var offsetVal = CGSizeMake(2.0, 2.0)
    
            var layerPath = UIBezierPath.bezierPathWithRoundedRect(rect= generatedView.bounds, byRoundingCorners = UIRectCornerAllCorners, cornerRadii = size ).CGPath
    
            var shadowLayer = CAShapeLayer().apply {
                path = layerPath
                fillColor = UIColor.whiteColor.CGColor
                shadowColor = UIColor.blackColor.CGColor
                shadowPath = layerPath
                shadowOffset = offsetVal
                shadowOpacity = 1.0F
                shadowRadius = 5.0
            }
    
            generatedView.layer.addSublayer(shadowLayer)
    
            return generatedView
    
        }
    Looking at some swift code, I guess that my translation to kotlin is correct, but I still dont get what it should output.. any ideas?
    r
    • 2
    • 21
  • m

    Matouš Skála

    03/28/2020, 1:35 PM
    Hi, we are having issues with the latest Xcode 11.4 when switching targets between simulators and device. We use the approach described in https://play.kotlinlang.org/hands-on/Targeting%20iOS%20and%20Android%20with%20Kotlin%20Multiplatform/06_SettingUpKotlinFramework to load the framework for the corresponding architecture in build phase. But it looks like the latest Xcode validates target integrity before running build phases, so the only workaround is to clean the build folder manually whenever the build target is changed, which is annoying. Has anyone found a better solution?
    r
    s
    • 3
    • 8
  • r

    Rostislav Utrobin

    04/02/2020, 5:57 AM
    Hi there! Do you have any advice how to debug Kotlin Native? For now i’m debugging my code from my Android app (so it’s jvm part only) and the only way to debug native part is to use print() statement and look to Xcode console. Is there any other way to debug native part?
    j
    • 2
    • 1
  • m

    magnumrocha

    04/08/2020, 8:00 AM
    currently, I'm trying to translate this code to kotlin:
    public func isConnectedToNetwork() -> Bool {
        var zeroAddress = sockaddr_in()
        zeroAddress.sin_len = UInt8(MemoryLayout<sockaddr_in>.size)
        zeroAddress.sin_family = sa_family_t(AF_INET)
    
        guard let defaultRouteReachability = withUnsafePointer(to: &zeroAddress, {
            $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
                SCNetworkReachabilityCreateWithAddress(nil, $0)
            }
        }) else {
            return false
        }
    
        var flags: SCNetworkReachabilityFlags = []
        if !SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) {
            return false
        }
        if flags.isEmpty {
            return false
        }
    
        let isReachable = flags.contains(.reachable)
        let needsConnection = flags.contains(.connectionRequired)
    
        return (isReachable && !needsConnection)
    }
    f
    • 2
    • 2
  • r

    Rostislav Utrobin

    04/08/2020, 8:37 AM
    Hi there! I use kotlin.cocoapods plugin to import my shared code into my ios project (as described here https://github.com/JetBrains/kotlin-native/blob/master/COCOAPODS.md). My script_phases section in .podspec file:
    spec.script_phases = [
        {
            :name => 'Build multiplatform',
            :execution_position => :before_compile,
            :shell_path => '/bin/sh',
            :script => <<-SCRIPT
                set -ev
                REPO_ROOT="$PODS_TARGET_SRCROOT"
                "$REPO_ROOT/../gradlew" -p "$REPO_ROOT" :multiplatform:syncFramework \
                    -Pkotlin.native.cocoapods.target=$KOTLIN_TARGET \
                    -Pkotlin.native.cocoapods.configuration=RELEASE \
                    -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" \
                    -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" \
                    -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS"
            SCRIPT
        }
    ]
    When I build my ios project it runs
    syncFramework
    task and I don’t understand how syncFramework works. Here are few examples: 1. I add some
    println("")
    inside a SharedCode function and when I build ios project the
    syncFramework
    does nothing. (I don’t see my println at runtime) 2. I change some function name
    fun test()
    ->
    fun myTest()
    then Xcode says
    test()
    func isn’t exist and if I change it to
    myTest()
    it compiles and crushes at runtime with
    unrecognized selector sent to instance
    For now the only way to rebuild all the project it to delete the build folder from SharedCode and run Xcode build again. Does it work as expected?
    m
    • 2
    • 13
Powered by Linen
Title
r

Rostislav Utrobin

04/08/2020, 8:37 AM
Hi there! I use kotlin.cocoapods plugin to import my shared code into my ios project (as described here https://github.com/JetBrains/kotlin-native/blob/master/COCOAPODS.md). My script_phases section in .podspec file:
spec.script_phases = [
    {
        :name => 'Build multiplatform',
        :execution_position => :before_compile,
        :shell_path => '/bin/sh',
        :script => <<-SCRIPT
            set -ev
            REPO_ROOT="$PODS_TARGET_SRCROOT"
            "$REPO_ROOT/../gradlew" -p "$REPO_ROOT" :multiplatform:syncFramework \
                -Pkotlin.native.cocoapods.target=$KOTLIN_TARGET \
                -Pkotlin.native.cocoapods.configuration=RELEASE \
                -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" \
                -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" \
                -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS"
        SCRIPT
    }
]
When I build my ios project it runs
syncFramework
task and I don’t understand how syncFramework works. Here are few examples: 1. I add some
println("")
inside a SharedCode function and when I build ios project the
syncFramework
does nothing. (I don’t see my println at runtime) 2. I change some function name
fun test()
->
fun myTest()
then Xcode says
test()
func isn’t exist and if I change it to
myTest()
it compiles and crushes at runtime with
unrecognized selector sent to instance
For now the only way to rebuild all the project it to delete the build folder from SharedCode and run Xcode build again. Does it work as expected?
m

magnumrocha

04/08/2020, 8:40 AM
the
syncFramework
task basically make a copy of the produced framework on your KMP module build folder to the Pod local framework folder
when you build your KMP library, an Apple framework is produced in the module's build folder...
the
syncFramework
task is added as a build step in XCode for the Pod that represents your library....
r

Rostislav Utrobin

04/08/2020, 8:46 AM
When I delete KMP build folder and run Xcode build the build folder (with Apple framework) will be created during the build. Who exactly will compile the framework?
m

magnumrocha

04/08/2020, 8:47 AM
the
syncFramework
task depends on
build
task in gradle
so, If the KMP is not built yet, the
build
will runs before the
syncFramework
r

Rostislav Utrobin

04/08/2020, 8:52 AM
Ok. What if KMP was built already. Does the
build
task understand that code was changed and it should recompile the framework ?
m

magnumrocha

04/08/2020, 8:54 AM
well, is that what is expected, but I always build my KMP module by hand when I change any code on it
and then I go to XCode...
r

Rostislav Utrobin

04/08/2020, 9:01 AM
Got it. I want to reach the flow: I start build in Xcode.
build
task sees the code was changed and recompile it (or just uses existed code if wasn’t changed)
m

magnumrocha

04/08/2020, 9:03 AM
flow =
XCode build
->
KMP Pod build
->
syncFramework
->
KMP Lib build in gradle
(if not already build)
r

Rostislav Utrobin

04/08/2020, 9:11 AM
Yeah. But I want the flow =
Xcode build
->
KMP Pod build
->
syncFramework
->
KMP Lib build in gradle
(if not already built or my KMP code has any changes since last build)
m

magnumrocha

04/08/2020, 9:17 AM
👍
View count: 6