https://kotlinlang.org logo
Title
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

Nikolay Kasyanov

02/11/2022, 7:31 AM
Yes, it’s a limitation of Objective C “generics”
s

Sam

02/11/2022, 12:24 PM
It's actually an ObjectiveC thing. NSArray and NSDictionary can't contain null values. It’s one of the few times that the language cares about when a value is null.
😢 1
🆒 1
👍 1
b

Brian Guertin

02/11/2022, 5:46 PM
I see, guess that won't be fixed unless there is true Swift interop in the future. For now I guess I'll just have to use a magic value to represent a "KotlinNull" and then swap it back to null on the Kotlin side or something 🤷‍♂️
n

Nikolay Kasyanov

02/14/2022, 7:43 AM
@Brian Guertin sounds like
NSNull
👆 1
👀 1