From 1e1ae8fd25fd633305738c98515f8f46fc08251d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 26 Aug 2016 00:31:14 -0700 Subject: [PATCH] [ios, macos] Fixed roundtripping enum values Also support unsetting enumeration-typed properties. --- .../darwin/src/MGLStyleAttributeFunction_Private.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/platform/darwin/src/MGLStyleAttributeFunction_Private.h b/platform/darwin/src/MGLStyleAttributeFunction_Private.h index 996f9e747..92dec0d4a 100644 --- a/platform/darwin/src/MGLStyleAttributeFunction_Private.h +++ b/platform/darwin/src/MGLStyleAttributeFunction_Private.h @@ -20,24 +20,28 @@ [(MGLStyleAttributeFunction *)name base].floatValue, \ }; \ self.layer->set##Name(function); \ - } else { \ + } else if (name) { \ NSAssert([name isKindOfClass:[NSValue class]], @"" #name @"should be an NSValue"); \ ObjCType value; \ [(NSValue *)name getValue:&value]; \ self.layer->set##Name({ static_cast(value) }); \ + } else { \ + self.layer->set##Name({}); \ } #define MGLGetEnumProperty(Name, MBGLType, ObjCType) \ const char *type = @encode(ObjCType); \ mbgl::style::PropertyValue property = self.layer->get##Name() ?: self.layer->getDefault##Name(); \ if (property.isConstant()) { \ - return [NSValue value:&property.asConstant() withObjCType:type]; \ + ObjCType value = static_cast(property.asConstant()); \ + return [NSValue value:&value withObjCType:type]; \ } else if (property.isFunction()) { \ MGLStyleAttributeFunction *function = [[MGLStyleAttributeFunction alloc] init]; \ auto stops = property.asFunction().getStops(); \ NSMutableDictionary *convertedStops = [NSMutableDictionary dictionaryWithCapacity:stops.size()]; \ for (auto stop : stops) { \ - convertedStops[@(stop.first)] = [NSValue value:&stop.second withObjCType:type]; \ + ObjCType value = static_cast(stop.second); \ + convertedStops[@(stop.first)] = [NSValue value:&value withObjCType:type]; \ } \ function.base = @(property.asFunction().getBase()); \ function.stops = convertedStops; \