just refreshed my memory on stuff i haven’t looked...
# kotlin-native
j
just refreshed my memory on stuff i haven’t looked at since ObjC days.
Int
on iOS is arch dependent and a bunch of articles seem to recommend using
Int
despite that all iPhones and iPads since 2013 and Watches since 2015 are now 64-bit. So….assuming I don’t want to burden API callers with the difference, is there a smart way to pass Swift
Int
down and handle it appropriately in the following case?
Copy code
let value = 5 // value is of type Int, so platform dependent

print("before: \(value)")
print("after: \(HelloKt.plusplus(value: value))")
// Cannot convert value of type 'Int' to expected argument type 'Int32'
in commonMain:
Copy code
fun plusplus(value: Int): Int {
    return value + 1
}

fun plusplus(value: Long): Long {
    return value + 1
}
map to
Copy code
+ (int32_t)plusplusValue__:(int32_t)value __attribute__((swift_name("plusplus(value__:)")));
+ (int64_t)plusplusValue___:(int64_t)value __attribute__((swift_name("plusplus(value___:)")));
respectively in iosMain:
Copy code
fun plusplus(value: integer_t): integer_t {
    return value + 1
}

fun plusplus(value: NSInteger): NSInteger {
    return value + 1
}
map to
Copy code
public typealias NSInteger = kotlin.Long // 64 bit signed
public typealias integer_t = <http://kotlin.Int|kotlin.Int> // 32 bit signed
respectively Any ideas?
r
One trick when hitting
NSInteger
APIs in obj-c is to use
convert()
at the obj-c/kotlin interface which can help make APIs size-agnostic. See eg https://github.com/russhwolf/multiplatform-settings/blob/master/multiplatform-settings/src/iosMain/kotlin/com/russhwolf/settings/AppleSettings.kt#L83-L97 which is used for all iOS variants
j
nice, that works from Kotlin to Obj-C boundaries, unfortunately i’m trying the other direction: from Obj-C to Kotlin