If I have List<Int> and there will be no nul...
# kotlin-native
k
If I have List<Int> and there will be no nulls inside it, is there way that interface in framework will be [NSNumber]?
s
What do you mean? Could you clarify?
k
@svyatoslav.scherbina If kotlin code have field List<Int>?, then it is compiled to [MyLibInt] in framework. I want that it will compile to [NSNumber] like in kn0.7
MyLibInt extends MyLibNumber, which extend NSNumber
s
MyLibInt extends MyLibNumber, which extend NSNumber
Exactly. And this means that you can apply to
[MyLibInt]
any operation that is allowed for
[NSNumber]
. So what’s the reason to have
[NSNumber]
instead of
[MyLibInt]
?
k
I can't cast [Uint8] to [MyLibInt], but I could cast [Uint8] to [NSNumber]
Now only way is to convert each element one by one with numericCast
s
Is your field writable?
k
yes, it is var
Hm.. will it work, if i specify type as List<UInt>? That will work for me.
s
If it is
var
, then it is incorrect to translate it as
[NSNumber]
, because otherwise it would be possible to pass e.g. list of
Double
instead of list of
Int
, and Swift compiler wouldn’t help to prevent this.
E.g.
Copy code
// Kotlin
var list: List<Int> = emptyList()
Copy code
// Swift
Kotlin.list = [0.5]
k
I tried to do it in constructor(myfield: List<Int>?), and it still converted to [MyLibInt]
s
Exactly, because otherwise it would be possible to pass list of doubles to this constructor, and this is incorrect.
k
Is there any way to make constructor parameter look like [UInt8] to swift side?
s
It is not possible currently.
k
ok, thx