Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Immutable source and style layer collections - #7539

Merged
1ec5 merged 2 commits into
release-ios-v3.4.0from
1ec5-style-layers-immutable-7459
Jan 5, 2017
Merged

1ec5 merged 2 commits into
release-ios-v3.4.0from
1ec5-style-layers-immutable-7459

Conversation

@1ec5

@1ec5 1ec5 commented Dec 23, 2016

Copy link
Copy Markdown
Contributor

MGLStyle’s sources and layers properties are now immutable collections but remain writable. Now Swift developers will see layers’ type as [MGLStyleLayer], not NSMutableArray. If you need a mutable array of layers, use -mutableArrayValueForKey:.

Fixes #7459.

/cc @bsudekum

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling labels Dec 23, 2016
@1ec5 1ec5 added this to the ios-v3.4.0 milestone Dec 23, 2016
@1ec5 1ec5 self-assigned this Dec 23, 2016
@1ec5
1ec5 requested a review from friedbunny December 23, 2016 23:19
@mention-bot

Copy link
Copy Markdown

@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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these mutable collections in the implementation be sent copy when returned?

@1ec5 1ec5 Jan 4, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention that it is possible to get a mutable copy as noted in #7459 (comment)?

@1ec5 1ec5 Jan 3, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-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.

1ec5 added 2 commits January 5, 2017 09:53
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.
@1ec5
1ec5 force-pushed the 1ec5-style-layers-immutable-7459 branch from b4182c8 to 653d320 Compare January 5, 2017 18:00
@1ec5
1ec5 merged commit 4700c72 into release-ios-v3.4.0 Jan 5, 2017
@1ec5
1ec5 deleted the 1ec5-style-layers-immutable-7459 branch January 5, 2017 18:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants