Repository navigation
Immutable source and style layer collections - #7539
Conversation
|
@1ec5, thanks for your PR! By analyzing this pull request, we identified @boundsj, @friedbunny and @incanus to be potential reviewers. |
| MGLSource *source = [self sourceFromMBGLSource:*rawSource]; | ||
| [sources addObject:source]; | ||
| } | ||
| return sources; |
There was a problem hiding this comment.
Should these mutable collections in the implementation be sent copy when returned?
There was a problem hiding this comment.
I’d prefer to return the mutable array here instead of incurring the potential cost of a copy, because the variable that holds the array has local scope and the declared return type is immutable. It would be a programming error for the caller to cast the object to an NSMutableArray, even conditionally, and this class would be unaffected even if it did.
| A set containing the style’s sources. | ||
| */ | ||
| @property (nonatomic, strong) NS_MUTABLE_SET_OF(MGLSource *) *sources; | ||
| @property (nonatomic, strong) NS_SET_OF(__kindof MGLSource *) *sources; |
There was a problem hiding this comment.
Should we mention that it is possible to get a mutable copy as noted in #7459 (comment)?
There was a problem hiding this comment.
-mutableArrayValueForKey: and -mutableSetValueForKey: are available to all KVC-compliant, array- or set-typed properties. The fact that they happen to be optimized for these two properties is an implementation detail. But if we can think of a good reason to use one or the other in an example, I'd be all for that.
If you need a mutable array of layers, use -mutableArrayValueForKey:.
Refined the types of MGLStyle’s sources and layers types so that Objective-C code can easily send messages intended for subclasses of MGLSource or MGLStyleLayer that are contained in one of these containers.
b4182c8 to
653d320
Compare
MGLStyle’s
sourcesandlayersproperties are now immutable collections but remain writable. Now Swift developers will seelayers’ type as[MGLStyleLayer], notNSMutableArray. If you need a mutable array of layers, use-mutableArrayValueForKey:.Fixes #7459.
/cc @bsudekum