diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-11-01 22:48:37 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-11-02 12:40:40 -0700 |
commit | e2797d1f24ac9ea5436921f97fbdac0ddc39d51b (patch) | |
tree | 3f5d6eabf2a42b0451d4b4033fb428ddcea511ca | |
parent | c2e37f062be6848a73eb5659f253775aa0abfe02 (diff) | |
download | qtlocation-mapboxgl-e2797d1f24ac9ea5436921f97fbdac0ddc39d51b.tar.gz |
[ios, macos] Rationalized string enum names
Renamed MGLGeoJSONSourceOption and MGLOfflinePackUserInfoKey constants for clarity and to remove redundancy in the Swift-bridged names. Left the old MGLOfflinePackUserInfoKey constants in place as deprecated aliases.
-rw-r--r-- | platform/darwin/src/MGLGeoJSONSource.h | 18 | ||||
-rw-r--r-- | platform/darwin/src/MGLGeoJSONSource.mm | 31 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.h | 22 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.mm | 28 | ||||
-rw-r--r-- | platform/darwin/src/MGLTypes.h | 2 | ||||
-rw-r--r-- | platform/darwin/test/MGLOfflineStorageTests.m | 4 | ||||
-rw-r--r-- | platform/ios/test/MGLGeoJSONSourceTests.mm | 14 |
7 files changed, 62 insertions, 57 deletions
diff --git a/platform/darwin/src/MGLGeoJSONSource.h b/platform/darwin/src/MGLGeoJSONSource.h index 67c6301bfc..30232c6211 100644 --- a/platform/darwin/src/MGLGeoJSONSource.h +++ b/platform/darwin/src/MGLGeoJSONSource.h @@ -16,29 +16,29 @@ typedef NSString *MGLGeoJSONSourceOption NS_STRING_ENUM; If the `features` property contains point features, setting this option to `YES` clusters the points by radius into groups. The default value is `NO`. */ -extern MGLGeoJSONSourceOption const MGLGeoJSONClusterOption; +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClustered; /** An `NSNumber` object containing an integer; specifies the radius of each cluster if clustering is enabled. A value of 512 produces a radius equal to the width of a tile. The default value is 50. */ -extern MGLGeoJSONSourceOption const MGLGeoJSONClusterRadiusOption; +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClusterRadius; /** An `NSNumber` object containing an integer; specifies the maximum zoom level at which to cluster points if clustering is enabled. Defaults to one zoom level - less than the value of `MGLGeoJSONMaximumZoomLevelOption` so that, at the + less than the value of `MGLGeoJSONSourceOptionMaximumZoomLevel` so that, at the maximum zoom level, the features are not clustered. */ -extern MGLGeoJSONSourceOption const MGLGeoJSONClusterMaximumZoomLevelOption; +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevelForClustering; /** An `NSNumber` object containing an integer; specifies the maximum zoom level at which to create vector tiles. A greater value produces greater detail at high zoom levels. The default value is 18. */ -extern MGLGeoJSONSourceOption const MGLGeoJSONMaximumZoomLevelOption; +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevel; /** An `NSNumber` object containing an integer; specifies the size of the tile @@ -46,14 +46,14 @@ extern MGLGeoJSONSourceOption const MGLGeoJSONMaximumZoomLevelOption; buffer as wide as the tile itself. Larger values produce fewer rendering artifacts near tile edges and slower performance. The default value is 128. */ -extern MGLGeoJSONSourceOption const MGLGeoJSONBufferOption; +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer; /** An `NSNumber` object containing a double; specifies the Douglas-Peucker simplification tolerance. A greater value produces simpler geometries and improves performance. The default value is 0.375. */ -extern MGLGeoJSONSourceOption const MGLGeoJSONToleranceOption; +extern const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance; /** A GeoJSON source. @@ -103,7 +103,7 @@ extern MGLGeoJSONSourceOption const MGLGeoJSONToleranceOption; @param options An `NSDictionary` of options for this source. @return An initialized GeoJSON source. */ -- (instancetype)initWithIdentifier:(NSString *)identifier features:(NSArray<id<MGLFeature>> *)features options:(nullable NS_DICTIONARY_OF(MGLGeoJSONSourceOption,id) *)options NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithIdentifier:(NSString *)identifier features:(NSArray<id<MGLFeature>> *)features options:(nullable NS_DICTIONARY_OF(MGLGeoJSONSourceOption, id) *)options NS_DESIGNATED_INITIALIZER; #pragma mark Accessing a Source’s Content @@ -120,7 +120,7 @@ extern MGLGeoJSONSourceOption const MGLGeoJSONToleranceOption; A GeoJSON representation of the contents of the source. Use the `features` property instead to get an object representation of the - contents. Alternatively, use NSJSONSerialization with the value of this + contents. Alternatively, use `NSJSONSerialization` with the value of this property to transform it into Foundation types. If the receiver was initialized using `-initWithIdentifier:URL:options` or diff --git a/platform/darwin/src/MGLGeoJSONSource.mm b/platform/darwin/src/MGLGeoJSONSource.mm index 3efcd59ae2..0dbe1030c6 100644 --- a/platform/darwin/src/MGLGeoJSONSource.mm +++ b/platform/darwin/src/MGLGeoJSONSource.mm @@ -8,13 +8,12 @@ #include <mbgl/style/sources/geojson_source.hpp> - -NSString * const MGLGeoJSONClusterOption = @"MGLGeoJSONCluster"; -NSString * const MGLGeoJSONClusterRadiusOption = @"MGLGeoJSONClusterRadius"; -NSString * const MGLGeoJSONClusterMaximumZoomLevelOption = @"MGLGeoJSONClusterMaximumZoomLevel"; -NSString * const MGLGeoJSONMaximumZoomLevelOption = @"MGLGeoJSONMaximumZoomLevel"; -NSString * const MGLGeoJSONBufferOption = @"MGLGeoJSONBuffer"; -NSString * const MGLGeoJSONToleranceOption = @"MGLGeoJSONOptionsClusterTolerance"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClustered = @"MGLGeoJSONSourceOptionClustered"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionClusterRadius = @"MGLGeoJSONSourceOptionClusterRadius"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevelForClustering = @"MGLGeoJSONSourceOptionMaximumZoomLevelForClustering"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionMaximumZoomLevel = @"MGLGeoJSONSourceOptionMaximumZoomLevel"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionBuffer = @"MGLGeoJSONSourceOptionBuffer"; +const MGLGeoJSONSourceOption MGLGeoJSONSourceOptionSimplificationTolerance = @"MGLGeoJSONSourceOptionSimplificationTolerance"; @interface MGLGeoJSONSource () @@ -97,38 +96,32 @@ NSString * const MGLGeoJSONToleranceOption = @"MGLGeoJSONOptionsClusterTolerance { auto mbglOptions = mbgl::style::GeoJSONOptions(); - if (self.options[MGLGeoJSONMaximumZoomLevelOption]) { - id value = self.options[MGLGeoJSONMaximumZoomLevelOption]; + if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevel]) { [self validateValue:value]; mbglOptions.maxzoom = [value integerValue]; } - if (self.options[MGLGeoJSONBufferOption]) { - id value = self.options[MGLGeoJSONBufferOption]; + if (id value = self.options[MGLGeoJSONSourceOptionBuffer]) { [self validateValue:value]; mbglOptions.buffer = [value integerValue]; } - if (self.options[MGLGeoJSONToleranceOption]) { - id value = self.options[MGLGeoJSONToleranceOption]; + if (id value = self.options[MGLGeoJSONSourceOptionSimplificationTolerance]) { [self validateValue:value]; mbglOptions.tolerance = [value doubleValue]; } - if (self.options[MGLGeoJSONClusterRadiusOption]) { - id value = self.options[MGLGeoJSONClusterRadiusOption]; + if (id value = self.options[MGLGeoJSONSourceOptionClusterRadius]) { [self validateValue:value]; mbglOptions.clusterRadius = [value integerValue]; } - if (self.options[MGLGeoJSONClusterMaximumZoomLevelOption]) { - id value = self.options[MGLGeoJSONClusterMaximumZoomLevelOption]; + if (id value = self.options[MGLGeoJSONSourceOptionMaximumZoomLevelForClustering]) { [self validateValue:value]; mbglOptions.clusterMaxZoom = [value integerValue]; } - if (self.options[MGLGeoJSONClusterOption]) { - id value = self.options[MGLGeoJSONClusterOption]; + if (id value = self.options[MGLGeoJSONSourceOptionClustered]) { [self validateValue:value]; mbglOptions.cluster = [value boolValue]; } diff --git a/platform/darwin/src/MGLOfflineStorage.h b/platform/darwin/src/MGLOfflineStorage.h index c6676cf0bd..b3fb7a2d54 100644 --- a/platform/darwin/src/MGLOfflineStorage.h +++ b/platform/darwin/src/MGLOfflineStorage.h @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN alternatively observe KVO change notifications to the pack’s `progress` key path. */ -extern NSNotificationName const MGLOfflinePackProgressChangedNotification; +extern const NSNotificationName MGLOfflinePackProgressChangedNotification; /** Posted by the shared `MGLOfflineStorage` object whenever an `MGLOfflinePack` @@ -37,7 +37,7 @@ extern NSNotificationName const MGLOfflinePackProgressChangedNotification; `userInfo` dictionary contains the error object in the `MGLOfflinePackErrorUserInfoKey` key. */ -extern NSNotificationName const MGLOfflinePackErrorNotification; +extern const NSNotificationName MGLOfflinePackErrorNotification; /** Posted by the shared `MGLOfflineStorage` object when the maximum number of @@ -52,7 +52,7 @@ extern NSNotificationName const MGLOfflinePackErrorNotification; calling the `-[MGLOfflineStorage removePack:withCompletionHandler:]` method. Contact your Mapbox sales representative to have the limit raised. */ -extern NSNotificationName const MGLOfflinePackMaximumMapboxTilesReachedNotification; +extern const NSNotificationName MGLOfflinePackMaximumMapboxTilesReachedNotification; /** A key in the `userInfo` property of a notification posted by `MGLOfflinePack`. @@ -65,7 +65,9 @@ typedef NSString *MGLOfflinePackUserInfoKey NS_EXTENSIBLE_STRING_ENUM; `MGLOfflinePackProgressChangedNotification` notification. Call `-integerValue` on the object to receive the `MGLOfflinePackState`-typed state. */ -extern MGLOfflinePackUserInfoKey const MGLOfflinePackStateUserInfoKey; +extern const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyState; + +extern NSString * const MGLOfflinePackStateUserInfoKey __attribute__((deprecated("Use MGLOfflinePackUserInfoKeyState"))); /** The key for an `NSValue` object that indicates an offline pack’s current @@ -74,7 +76,9 @@ extern MGLOfflinePackUserInfoKey const MGLOfflinePackStateUserInfoKey; `-MGLOfflinePackProgressValue` on the object to receive the `MGLOfflinePackProgress`-typed progress. */ -extern MGLOfflinePackUserInfoKey const MGLOfflinePackProgressUserInfoKey; +extern const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyProgress; + +extern NSString * const MGLOfflinePackProgressUserInfoKey __attribute__((deprecated("Use MGLOfflinePackUserInfoKeyProgress"))); /** The key for an `NSError` object that is encountered in the course of @@ -82,7 +86,9 @@ extern MGLOfflinePackUserInfoKey const MGLOfflinePackProgressUserInfoKey; an `MGLOfflinePackErrorNotification` notification. The error’s domain is `MGLErrorDomain`. See `MGLErrorCode` for possible error codes. */ -extern MGLOfflinePackUserInfoKey const MGLOfflinePackErrorUserInfoKey; +extern const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyError; + +extern NSString * const MGLOfflinePackErrorUserInfoKey __attribute__((deprecated("Use MGLOfflinePackUserInfoKeyError"))); /** The key for an `NSNumber` object that indicates the maximum number of @@ -92,7 +98,9 @@ extern MGLOfflinePackUserInfoKey const MGLOfflinePackErrorUserInfoKey; `-unsignedLongLongValue` on the object to receive the `uint64_t`-typed tile limit. */ -extern MGLOfflinePackUserInfoKey const MGLOfflinePackMaximumCountUserInfoKey; +extern const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyMaximumCount; + +extern NSString * const MGLOfflinePackMaximumCountUserInfoKey __attribute__((deprecated("Use MGLOfflinePackUserInfoKeyMaximumCount"))); /** A block to be called once an offline pack has been completely created and diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm index 5f284b76a1..10acc58b25 100644 --- a/platform/darwin/src/MGLOfflineStorage.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -13,14 +13,18 @@ static NSString * const MGLOfflineStorageFileName = @"cache.db"; static NSString * const MGLOfflineStorageFileName3_2_0_beta_1 = @"offline.db"; -NSString * const MGLOfflinePackProgressChangedNotification = @"MGLOfflinePackProgressChanged"; -NSString * const MGLOfflinePackErrorNotification = @"MGLOfflinePackError"; -NSString * const MGLOfflinePackMaximumMapboxTilesReachedNotification = @"MGLOfflinePackMaximumMapboxTilesReached"; - -NSString * const MGLOfflinePackStateUserInfoKey = @"State"; -NSString * const MGLOfflinePackProgressUserInfoKey = @"Progress"; -NSString * const MGLOfflinePackErrorUserInfoKey = @"Error"; -NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount"; +const NSNotificationName MGLOfflinePackProgressChangedNotification = @"MGLOfflinePackProgressChanged"; +const NSNotificationName MGLOfflinePackErrorNotification = @"MGLOfflinePackError"; +const NSNotificationName MGLOfflinePackMaximumMapboxTilesReachedNotification = @"MGLOfflinePackMaximumMapboxTilesReached"; + +const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyState = @"State"; +NSString * const MGLOfflinePackStateUserInfoKey = MGLOfflinePackUserInfoKeyState; +const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyProgress = @"Progress"; +NSString * const MGLOfflinePackProgressUserInfoKey = MGLOfflinePackUserInfoKeyProgress; +const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyError = @"Error"; +NSString * const MGLOfflinePackErrorUserInfoKey = MGLOfflinePackUserInfoKeyError; +const MGLOfflinePackUserInfoKey MGLOfflinePackUserInfoKeyMaximumCount = @"MaximumCount"; +NSString * const MGLOfflinePackMaximumCountUserInfoKey = MGLOfflinePackUserInfoKeyMaximumCount; @interface MGLOfflineStorage () <MGLOfflinePackDelegate> @@ -317,20 +321,20 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount"; - (void)offlinePack:(MGLOfflinePack *)pack progressDidChange:(__unused MGLOfflinePackProgress)progress { [[NSNotificationCenter defaultCenter] postNotificationName:MGLOfflinePackProgressChangedNotification object:pack userInfo:@{ - MGLOfflinePackStateUserInfoKey: @(pack.state), - MGLOfflinePackProgressUserInfoKey: [NSValue valueWithMGLOfflinePackProgress:progress], + MGLOfflinePackUserInfoKeyState: @(pack.state), + MGLOfflinePackUserInfoKeyProgress: [NSValue valueWithMGLOfflinePackProgress:progress], }]; } - (void)offlinePack:(MGLOfflinePack *)pack didReceiveError:(NSError *)error { [[NSNotificationCenter defaultCenter] postNotificationName:MGLOfflinePackErrorNotification object:pack userInfo:@{ - MGLOfflinePackErrorUserInfoKey: error, + MGLOfflinePackUserInfoKeyError: error, }]; } - (void)offlinePack:(MGLOfflinePack *)pack didReceiveMaximumAllowedMapboxTiles:(uint64_t)maximumCount { [[NSNotificationCenter defaultCenter] postNotificationName:MGLOfflinePackMaximumMapboxTilesReachedNotification object:pack userInfo:@{ - MGLOfflinePackMaximumCountUserInfoKey: @(maximumCount), + MGLOfflinePackUserInfoKeyMaximumCount: @(maximumCount), }]; } diff --git a/platform/darwin/src/MGLTypes.h b/platform/darwin/src/MGLTypes.h index a1367e2d61..e9e05bc684 100644 --- a/platform/darwin/src/MGLTypes.h +++ b/platform/darwin/src/MGLTypes.h @@ -98,7 +98,7 @@ NS_ASSUME_NONNULL_END #endif #endif -#if !defined(FOUNDATION_SWIFT_SDK_EPOCH_AT_LEAST) || !FOUNDATION_SWIFT_SDK_EPOCH_AT_LEAST(8) +#if !defined(FOUNDATION_SWIFT_SDK_EPOCH_LESS_THAN) || FOUNDATION_SWIFT_SDK_EPOCH_LESS_THAN(8) #define NS_STRING_ENUM #define NS_EXTENSIBLE_STRING_ENUM #define NSNotificationName NSString * diff --git a/platform/darwin/test/MGLOfflineStorageTests.m b/platform/darwin/test/MGLOfflineStorageTests.m index 8400cb43cb..cd13a9262e 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.m +++ b/platform/darwin/test/MGLOfflineStorageTests.m @@ -90,11 +90,11 @@ NSDictionary *userInfo = notification.userInfo; XCTAssertNotNil(userInfo, @"Progress change notification should have a userInfo dictionary."); - NSNumber *stateNumber = userInfo[MGLOfflinePackStateUserInfoKey]; + NSNumber *stateNumber = userInfo[MGLOfflinePackUserInfoKeyState]; XCTAssert([stateNumber isKindOfClass:[NSNumber class]], @"Progress change notification’s state should be an NSNumber."); XCTAssertEqual(stateNumber.integerValue, pack.state, @"State in a progress change notification should match the pack’s state."); - NSValue *progressValue = userInfo[MGLOfflinePackProgressUserInfoKey]; + NSValue *progressValue = userInfo[MGLOfflinePackUserInfoKeyProgress]; XCTAssert([progressValue isKindOfClass:[NSValue class]], @"Progress change notification’s progress should be an NSValue."); XCTAssertEqualObjects(progressValue, [NSValue valueWithMGLOfflinePackProgress:pack.progress], @"Progress change notification’s progress should match pack’s progress."); diff --git a/platform/ios/test/MGLGeoJSONSourceTests.mm b/platform/ios/test/MGLGeoJSONSourceTests.mm index 96431ad018..be8bb143ce 100644 --- a/platform/ios/test/MGLGeoJSONSourceTests.mm +++ b/platform/ios/test/MGLGeoJSONSourceTests.mm @@ -15,12 +15,12 @@ - (void)testMGLGeoJSONSourceWithOptions { NSURL *url = [NSURL URLWithString:@"http://www.mapbox.com/source"]; - NSDictionary *options = @{MGLGeoJSONClusterOption: @(YES), - MGLGeoJSONClusterRadiusOption: @42, - MGLGeoJSONClusterMaximumZoomLevelOption: @98, - MGLGeoJSONMaximumZoomLevelOption: @99, - MGLGeoJSONBufferOption: @1976, - MGLGeoJSONToleranceOption: @0.42}; + NSDictionary *options = @{MGLGeoJSONSourceOptionClustered: @YES, + MGLGeoJSONSourceOptionClusterRadius: @42, + MGLGeoJSONSourceOptionMaximumZoomLevelForClustering: @98, + MGLGeoJSONSourceOptionMaximumZoomLevel: @99, + MGLGeoJSONSourceOptionBuffer: @1976, + MGLGeoJSONSourceOptionSimplificationTolerance: @0.42}; MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" URL:url options:options]; auto mbglOptions = [source geoJSONOptions]; @@ -31,7 +31,7 @@ XCTAssertEqual(mbglOptions.buffer, 1976); XCTAssertEqual(mbglOptions.tolerance, 0.42); - options = @{MGLGeoJSONClusterOption: @"number 1"}; + options = @{MGLGeoJSONSourceOptionClustered: @"number 1"}; XCTAssertThrows([[MGLGeoJSONSource alloc] initWithIdentifier:@"source-id" URL:url options:options]); } |