jw
01/27/2023, 5:33 PMNSArrayAsKList
work? Are we basically just reinterpreting the pointer to the NSArray
as one of these instances on the C-side?interpretObjCPointer<NSMutableArrayAsKMutableList>(NSMutableArray().objcPtr()) as MutableList<E>
and it seemed to worksergey.bogolepov
02/01/2023, 3:25 PMAre we basically just reinterpreting the pointer to theNot quite.as one of these instances on the C-side?NSArray
NSArrayAsKList
is a proxy class. Its instances are created as “associated objects” when NSArray
is “crossing border” between Objective-C and Kotlin worlds.
So in this example we are wrapping/unwrapping Objective-C object several times.interpretObjCPointer<NSMutableArrayAsKMutableList>(NSMutableArray().objcPtr()) as MutableList<E>
Now I’m wondering why Darwin platforms don’t typealias ArrayList to this type and create an NSMutableArray instead of having a dedicated implementation of ArrayListThere are lots of reasons. To name a few: • We need to keep consistent behaviour between different targets. • As shown above, there is an overhead from interaction between 2 runtimes. • We don’t depend on whatever Apple will do to
NSMutableArray
.jw
02/01/2023, 3:56 PMsergey.bogolepov
02/01/2023, 4:38 PM