jrod
12/01/2019, 8:03 PMInt
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?
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:
fun plusplus(value: Int): Int {
return value + 1
}
fun plusplus(value: Long): Long {
return value + 1
}
map to
+ (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:
fun plusplus(value: integer_t): integer_t {
return value + 1
}
fun plusplus(value: NSInteger): NSInteger {
return value + 1
}
map to
public typealias NSInteger = kotlin.Long // 64 bit signed
public typealias integer_t = <http://kotlin.Int|kotlin.Int> // 32 bit signed
respectively
Any ideas?russhwolf
12/02/2019, 12:52 AMNSInteger
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 variantsjrod
12/03/2019, 12:34 AM