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

MGLShapeCollection.shapes should be writable #7458

Closed
1ec5 opened this issue Dec 15, 2016 · 9 comments
Closed

MGLShapeCollection.shapes should be writable #7458

1ec5 opened this issue Dec 15, 2016 · 9 comments
Labels
archived Archived because of inactivity feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented Dec 15, 2016

MGLShapeCollection’s shapes property should be a read-write mutable array, so that the developer can (for example) append a shape to the collection directly rather than having to create a new MGLShapeCollection to change the shapes within an MGLShapeSource.

The implementation would be similar in scope to #6160, although without any C++ wrangling.

/cc @bsudekum

@1ec5 1ec5 added feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling labels Dec 15, 2016
@1ec5 1ec5 added this to the ios-3.4.1 milestone Dec 15, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Dec 15, 2016

Making the array mutable would run into the same problem as #7459. But we can still make the property read-write without running into that problem.

@andrewstay
Copy link

@1ec5 It is very risky and considered as a bad design to provide mutable containers in the interface. Please consider adding following methods instead:

- (void)addShape:
- (void)removeShape:

@1ec5
Copy link
Contributor Author

1ec5 commented Dec 19, 2016

Thanks @andrewstay, in that case, we can certainly provide individual getters and setters without making the array mutable. This will likely be the solution to #7459 as well.

@1ec5 1ec5 changed the title MGLShapeCollection.shapes should be a mutable array MGLShapeCollection.shapes should be writable Dec 19, 2016
@1ec5 1ec5 modified the milestones: ios-v3.4.1, ios-v3.4.2 Jan 25, 2017
@1ec5 1ec5 modified the milestones: ios-v3.5.0, ios-v3.4.2 Feb 5, 2017
@1ec5 1ec5 modified the milestones: ios-v3.5.0, ios-v3.6.0 Mar 9, 2017
@boundsj boundsj modified the milestones: ios-future, ios-v3.6.0 Mar 31, 2017
@1ec5
Copy link
Contributor Author

1ec5 commented Apr 19, 2017

I think we should consider implementing the KVO methods for mutable containers. That way the developer can call the standard -[NSObject mutableArrayValueForKey:] then efficiently add and remove from that NSMutableArray without having to then set the shapes property at the end. We follow this pattern in MGLStyle.

@andrewgubanov
Copy link

@1ec5 The solution suggested by you looks like encapsulation violation as it exposes internal logic to the client.

@1ec5
Copy link
Contributor Author

1ec5 commented Apr 19, 2017

Would it be? I thought -mutableArrayValueForKey: etc. are intended to be used that way; implementing KVO methods like -insertObject:inShapesAtIndex: only improves their performance, but the developer doesn’t need to know about the KVO methods. To be clear, shapes would not be declared as mutable.

@andrewgubanov
Copy link

To make things cleaner:

  1. -mutableArrayValueForKey: is a part of the KVC, not KVO
  2. insertObject:inShapesAtIndex: is not a KVO
  3. KVC and KVO were intended to be used in unittests initially, but somehow migrated to the production code.

When user of your objects access private property with the knowledge that it is a mutable container and can modify it using KVC it is a direct violation of encapsulation and should be avoided as much as possible.

@1ec5
Copy link
Contributor Author

1ec5 commented Apr 19, 2017

Sorry for being thick: I was conflating KVC and KVO. In fact, I’m also overthinking things: the collection methods needed for -mutableArrayValueForKey: (if any) would be autosynthesized anyhow, since shapes itself is autosynthesized. If methods like -appendShape: and -removeShapeAtIndex: would be more discoverable and convenient than -mutableArrayValueForKey:, we can certainly do that – and it’d be consistent with MGLMultiPoint to boot.

@stale stale bot added the archived Archived because of inactivity label Nov 8, 2018
@stale
Copy link

stale bot commented Nov 27, 2018

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Nov 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived Archived because of inactivity feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling
Projects
None yet
Development

No branches or pull requests

4 participants