You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
MGLStyle.layers and .sources bridge to Swift as untyped collections #7459
MGLStyle.layers is typed as a read-write NSMutableArray of MGLStyleLayer objects, while MGLStyle.sources is typed as a read-write NSMutableSet of MGLSource objects. Ironically, Swift is unable to distinguish between a read-write NSArray property and a read-write NSMutableArray property (likewise for NSMutableSet), so the properties end up getting bridged as NSMutableArray and NSMutableSet, respectively, instead of [MGLStyleLayer] and [MGLSource].
We should find a way to ensure that Swift developers get the same type safety that Objective-C developers do. One option is to make these collections non-mutable but still implement the mutable KVC methods under the hood. Developers who want to work with the mutable property would then call -mutableArrayValueForKey: or -mutableSetValueForKey:. While workable, that’s hardly discoverable. On the other hand, we explicitly declare a number of non-KVC methods for layers that should reduce the need to work with the mutable array directly in code. Another option would be to define separate layers and mutableLayers properties, but that would double the number of code paths. Any other ideas?
Putting on the v3.4.0 milestone for now to consider our options. Depending on what we think the best option would be, we might be able to postpone this work until a patch release.
The most analogous API in Cocoa, NSView.subviews, is declared as a property of NSArray<__kindof NSView *> * type with copy semantics. We should make the layers property an NSArray and document that it is possible to get a mutable array using -mutableArrayValueForKey:, thanks to the key-value coding work in #6097.
At the same time, we should use the __kindof keyword with the layers and sources arrays, so that the following cast becomes unnecessary in Objective-C:
Activity
1ec5 commentedon Dec 18, 2016
The most analogous API in Cocoa,
NSView.subviews, is declared as a property ofNSArray<__kindof NSView *> *type with copy semantics. We should make thelayersproperty an NSArray and document that it is possible to get a mutable array using-mutableArrayValueForKey:, thanks to the key-value coding work in #6097.At the same time, we should use the
__kindofkeyword with thelayersandsourcesarrays, so that the following cast becomes unnecessary in Objective-C:boundsj commentedon Jan 8, 2017
This was fixed by #7539