summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLFeature.mm26
-rw-r--r--platform/darwin/src/MGLFeature_Private.h14
-rw-r--r--platform/darwin/test/MGLFeatureTests.mm6
3 files changed, 31 insertions, 15 deletions
diff --git a/platform/darwin/src/MGLFeature.mm b/platform/darwin/src/MGLFeature.mm
index 3b6a2ee488..d24c807625 100644
--- a/platform/darwin/src/MGLFeature.mm
+++ b/platform/darwin/src/MGLFeature.mm
@@ -25,11 +25,12 @@
@implementation MGLEmptyFeature
@synthesize identifier;
-@synthesize attributes;
+@synthesize attributes = _attributes;
MGL_DEFINE_FEATURE_INIT_WITH_CODER();
MGL_DEFINE_FEATURE_ENCODE();
MGL_DEFINE_FEATURE_IS_EQUAL();
+MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER();
- (id)attributeForKey:(NSString *)key {
MGLLogDebug(@"Retrieving attributeForKey: %@", key);
@@ -60,11 +61,12 @@ MGL_DEFINE_FEATURE_IS_EQUAL();
@implementation MGLPointFeature
@synthesize identifier;
-@synthesize attributes;
+@synthesize attributes = _attributes;
MGL_DEFINE_FEATURE_INIT_WITH_CODER();
MGL_DEFINE_FEATURE_ENCODE();
MGL_DEFINE_FEATURE_IS_EQUAL();
+MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER();
- (id)attributeForKey:(NSString *)key {
MGLLogDebug(@"Retrieving attributeForKey: %@", key);
@@ -96,11 +98,12 @@ MGL_DEFINE_FEATURE_IS_EQUAL();
@implementation MGLPolylineFeature
@synthesize identifier;
-@synthesize attributes;
+@synthesize attributes = _attributes;
MGL_DEFINE_FEATURE_INIT_WITH_CODER();
MGL_DEFINE_FEATURE_ENCODE();
MGL_DEFINE_FEATURE_IS_EQUAL();
+MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER();
- (id)attributeForKey:(NSString *)key {
MGLLogDebug(@"Retrieving attributeForKey: %@", key);
@@ -133,11 +136,12 @@ MGL_DEFINE_FEATURE_IS_EQUAL();
@implementation MGLPolygonFeature
@synthesize identifier;
-@synthesize attributes;
+@synthesize attributes = _attributes;
MGL_DEFINE_FEATURE_INIT_WITH_CODER();
MGL_DEFINE_FEATURE_ENCODE();
MGL_DEFINE_FEATURE_IS_EQUAL();
+MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER();
- (id)attributeForKey:(NSString *)key {
MGLLogDebug(@"Retrieving attributeForKey: %@", key);
@@ -170,11 +174,12 @@ MGL_DEFINE_FEATURE_IS_EQUAL();
@implementation MGLPointCollectionFeature
@synthesize identifier;
-@synthesize attributes;
+@synthesize attributes = _attributes;
MGL_DEFINE_FEATURE_INIT_WITH_CODER();
MGL_DEFINE_FEATURE_ENCODE();
MGL_DEFINE_FEATURE_IS_EQUAL();
+MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER();
- (id)attributeForKey:(NSString *)key {
MGLLogDebug(@"Retrieving attributeForKey: %@", key);
@@ -197,11 +202,12 @@ MGL_DEFINE_FEATURE_IS_EQUAL();
@implementation MGLMultiPolylineFeature
@synthesize identifier;
-@synthesize attributes;
+@synthesize attributes = _attributes;
MGL_DEFINE_FEATURE_INIT_WITH_CODER();
MGL_DEFINE_FEATURE_ENCODE();
MGL_DEFINE_FEATURE_IS_EQUAL();
+MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER();
- (id)attributeForKey:(NSString *)key {
MGLLogDebug(@"Retrieving attributeForKey: %@", key);
@@ -234,11 +240,12 @@ MGL_DEFINE_FEATURE_IS_EQUAL();
@implementation MGLMultiPolygonFeature
@synthesize identifier;
-@synthesize attributes;
+@synthesize attributes = _attributes;
MGL_DEFINE_FEATURE_INIT_WITH_CODER();
MGL_DEFINE_FEATURE_ENCODE();
MGL_DEFINE_FEATURE_IS_EQUAL();
+MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER();
- (id)attributeForKey:(NSString *)key {
MGLLogDebug(@"Retrieving attributeForKey: %@", key);
@@ -271,7 +278,7 @@ MGL_DEFINE_FEATURE_IS_EQUAL();
@implementation MGLShapeCollectionFeature
@synthesize identifier;
-@synthesize attributes;
+@synthesize attributes = _attributes;
@dynamic shapes;
@@ -282,6 +289,7 @@ MGL_DEFINE_FEATURE_IS_EQUAL();
MGL_DEFINE_FEATURE_INIT_WITH_CODER();
MGL_DEFINE_FEATURE_ENCODE();
MGL_DEFINE_FEATURE_IS_EQUAL();
+MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER();
- (id)attributeForKey:(NSString *)key {
return self.attributes[key];
@@ -463,7 +471,7 @@ mbgl::Feature mbglFeature(mbgl::Feature feature, id identifier, NSDictionary *at
NSDictionary<NSString *, id> *NSDictionaryFeatureForGeometry(NSDictionary *geometry, NSDictionary *attributes, id identifier) {
NSMutableDictionary *feature = [@{@"type": @"Feature",
- @"properties": (attributes) ?: [NSNull null],
+ @"properties": attributes,
@"geometry": geometry} mutableCopy];
feature[@"id"] = identifier;
return [feature copy];
diff --git a/platform/darwin/src/MGLFeature_Private.h b/platform/darwin/src/MGLFeature_Private.h
index d4074b53ed..9fb1f91820 100644
--- a/platform/darwin/src/MGLFeature_Private.h
+++ b/platform/darwin/src/MGLFeature_Private.h
@@ -31,7 +31,7 @@ MGLShape* MGLShapeFromGeoJSON(const mapbox::geojson::geojson &geojson);
returns the feature object with converted `mbgl::FeatureIdentifier` and
`mbgl::PropertyMap` properties.
*/
-mbgl::Feature mbglFeature(mbgl::Feature feature, id identifier, NSDictionary *attributes);
+mbgl::Feature mbglFeature(mbgl::Feature feature, id identifier, NSDictionary * attributes);
/**
Returns an `NSDictionary` representation of an `MGLFeature`.
@@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_END
if (self = [super initWithCoder:decoder]) { \
NSSet<Class> *identifierClasses = [NSSet setWithArray:@[[NSString class], [NSNumber class]]]; \
identifier = [decoder decodeObjectOfClasses:identifierClasses forKey:@"identifier"]; \
- attributes = [decoder decodeObjectOfClass:[NSDictionary class] forKey:@"attributes"]; \
+ _attributes = [decoder decodeObjectOfClass:[NSDictionary class] forKey:@"attributes"]; \
} \
return self; \
}
@@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_END
- (void)encodeWithCoder:(NSCoder *)coder { \
[super encodeWithCoder:coder]; \
[coder encodeObject:identifier forKey:@"identifier"]; \
- [coder encodeObject:attributes forKey:@"attributes"]; \
+ [coder encodeObject:_attributes forKey:@"attributes"]; \
}
#define MGL_DEFINE_FEATURE_IS_EQUAL() \
@@ -67,3 +67,11 @@ NS_ASSUME_NONNULL_END
- (NSUInteger)hash { \
return [super hash] + [[self geoJSONDictionary] hash]; \
}
+
+#define MGL_DEFINE_FEATURE_ATTRIBUTES_GETTER() \
+ - (NSDictionary *) attributes { \
+ if (!_attributes) { \
+ return @{}; \
+ } \
+ return _attributes; \
+ }
diff --git a/platform/darwin/test/MGLFeatureTests.mm b/platform/darwin/test/MGLFeatureTests.mm
index 3e8e47474b..67f2a9a45e 100644
--- a/platform/darwin/test/MGLFeatureTests.mm
+++ b/platform/darwin/test/MGLFeatureTests.mm
@@ -176,7 +176,7 @@
// it has no "id" key (or value)
XCTAssertNil(geoJSONFeature[@"id"]);
// it has a null representation of the properties object
- XCTAssertEqualObjects(geoJSONFeature[@"properties"], [NSNull null]);
+ XCTAssertEqualObjects(geoJSONFeature[@"properties"], @{});
// when there is a string identifier
pointFeature.identifier = @"string-id";
@@ -317,13 +317,13 @@
@"geometries": @[
@{ @"geometry": @{@"type": @"Point",
@"coordinates": @[@(pointCoordinate.longitude), @(pointCoordinate.latitude)]},
- @"properties": [NSNull null],
+ @"properties": @{},
@"type": @"Feature",
},
@{ @"geometry": @{@"type": @"LineString",
@"coordinates": @[@[@(coord1.longitude), @(coord1.latitude)],
@[@(coord2.longitude), @(coord2.latitude)]]},
- @"properties": [NSNull null],
+ @"properties": @{},
@"type": @"Feature",
}
]