summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLShapeCollection.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLShapeCollection.mm')
-rw-r--r--platform/darwin/src/MGLShapeCollection.mm30
1 files changed, 29 insertions, 1 deletions
diff --git a/platform/darwin/src/MGLShapeCollection.mm b/platform/darwin/src/MGLShapeCollection.mm
index e317a443fe..4b468a1cbb 100644
--- a/platform/darwin/src/MGLShapeCollection.mm
+++ b/platform/darwin/src/MGLShapeCollection.mm
@@ -12,12 +12,40 @@
- (instancetype)initWithShapes:(NS_ARRAY_OF(MGLShape *) *)shapes {
if (self = [super init]) {
- NSAssert(shapes.count, @"Cannot create an empty shape collection");
_shapes = shapes.copy;
}
return self;
}
+- (instancetype)initWithCoder:(NSCoder *)decoder {
+ if (self = [super initWithCoder:decoder]) {
+ _shapes = [decoder decodeObjectOfClass:[NSArray class] forKey:@"shapes"];
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)coder {
+ [super encodeWithCoder:coder];
+ [coder encodeObject:_shapes forKey:@"shapes"];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) return YES;
+ if (![other isKindOfClass:[MGLShapeCollection class]]) return NO;
+
+ MGLShapeCollection *otherShapeCollection = other;
+ return [super isEqual:otherShapeCollection]
+ && [_shapes isEqualToArray:otherShapeCollection.shapes];
+}
+
+- (NSUInteger)hash {
+ NSUInteger hash = [super hash];
+ for (MGLShape *shape in _shapes) {
+ hash += [shape hash];
+ }
+ return hash;
+}
+
- (CLLocationCoordinate2D)coordinate {
return _shapes.firstObject.coordinate;
}