summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-04-30 11:35:52 -0400
committerMinh Nguyễn <mxn@1ec5.org>2015-04-30 11:35:52 -0400
commit87c61657a12f41c8d32c85fc0e0fa525302ed614 (patch)
treee84498b62f13e6e49fc667ae2d0351e6bcf87b79 /platform
parentbbcc7c26d9862f4fb8685174330a73132d8c8a27 (diff)
downloadqtlocation-mapboxgl-87c61657a12f41c8d32c85fc0e0fa525302ed614.tar.gz
Objective-C niceties
Added macro for main thread assertions based on `NSAssert()`. Reworded Boolean property per Objective-C conventions.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLMapView.mm3
-rw-r--r--platform/ios/MGLMapboxEvents.m31
-rw-r--r--platform/ios/NSException+MGLAdditions.h3
3 files changed, 20 insertions, 17 deletions
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 3ee6ed0914..542838797f 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -20,6 +20,7 @@
#import "NSBundle+MGLAdditions.h"
#import "NSString+MGLAdditions.h"
#import "NSProcessInfo+MGLAdditions.h"
+#import "NSException+MGLAdditions.h"
#import "MGLAnnotation.h"
#import "MGLUserLocationAnnotationView.h"
#import "MGLUserLocation_Private.h"
@@ -2348,7 +2349,7 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng)
- (void)invalidate
{
- assert([[NSThread currentThread] isMainThread]);
+ MGLAssertIsMainThread();
[self.glView setNeedsDisplay];
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m
index cf8345222b..dcf1d0bab0 100644
--- a/platform/ios/MGLMapboxEvents.m
+++ b/platform/ios/MGLMapboxEvents.m
@@ -8,6 +8,7 @@
#import "MGLMetricsLocationManager.h"
#import "NSProcessInfo+MGLAdditions.h"
#import "NSBundle+MGLAdditions.h"
+#import "NSException+MGLAdditions.h"
#include <sys/sysctl.h>
@@ -83,9 +84,9 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
@property (atomic) NSData *geoTrustCert;
-// The isPaused state tracker is only ever accessed from the main thread.
+// The paused state tracker is only ever accessed from the main thread.
//
-@property (nonatomic) BOOL isPaused;
+@property (nonatomic, getter=isPaused) BOOL paused;
// The timer is only ever accessed from the main thread.
//
@@ -111,7 +112,7 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
// Must be called from the main thread. Only called internally.
//
- (instancetype) init {
- assert([[NSThread currentThread] isMainThread]);
+ MGLAssertIsMainThread();
self = [super init];
if (self) {
@@ -207,8 +208,6 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
// Enable Battery Monitoring
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
-
- _isPaused = NO;
}
return self;
}
@@ -242,39 +241,39 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
// Must be called from the main thread.
//
+ (void) setToken:(NSString *)token {
- assert([[NSThread currentThread] isMainThread]);
+ MGLAssertIsMainThread();
[MGLMapboxEvents sharedManager].token = token;
}
// Must be called from the main thread.
//
+ (void) setAppName:(NSString *)appName {
- assert([[NSThread currentThread] isMainThread]);
+ MGLAssertIsMainThread();
[MGLMapboxEvents sharedManager].appName = appName;
}
// Must be called from the main thread.
//
+ (void) setAppVersion:(NSString *)appVersion {
- assert([[NSThread currentThread] isMainThread]);
+ MGLAssertIsMainThread();
[MGLMapboxEvents sharedManager].appVersion = appVersion;
}
// Must be called from the main thread.
//
+ (void) setAppBuildNumber:(NSString *)appBuildNumber {
- assert([[NSThread currentThread] isMainThread]);
+ MGLAssertIsMainThread();
[MGLMapboxEvents sharedManager].appBuildNumber = appBuildNumber;
}
// Must be called from the main thread.
//
+ (void) pauseMetricsCollection {
- assert([[NSThread currentThread] isMainThread]);
- if ([MGLMapboxEvents sharedManager].isPaused) {
+ MGLAssertIsMainThread();
+ if ([MGLMapboxEvents sharedManager].paused) {
return;
}
- [MGLMapboxEvents sharedManager].isPaused = YES;
+ [MGLMapboxEvents sharedManager].paused = YES;
[MGLMetricsLocationManager stopUpdatingLocation];
[MGLMetricsLocationManager stopMonitoringVisits];
}
@@ -282,11 +281,11 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
// Must be called from the main thread.
//
+ (void) resumeMetricsCollection {
- assert([[NSThread currentThread] isMainThread]);
- if (![MGLMapboxEvents sharedManager].isPaused) {
+ MGLAssertIsMainThread();
+ if (![MGLMapboxEvents sharedManager].paused) {
return;
}
- [MGLMapboxEvents sharedManager].isPaused = NO;
+ [MGLMapboxEvents sharedManager].paused = NO;
[MGLMetricsLocationManager startUpdatingLocation];
[MGLMetricsLocationManager startMonitoringVisits];
}
@@ -323,7 +322,7 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
}
// Metrics Collection Has Been Paused
- if (_isPaused) {
+ if (_paused) {
return;
}
diff --git a/platform/ios/NSException+MGLAdditions.h b/platform/ios/NSException+MGLAdditions.h
new file mode 100644
index 0000000000..4d5de15116
--- /dev/null
+++ b/platform/ios/NSException+MGLAdditions.h
@@ -0,0 +1,3 @@
+#import <Foundation/Foundation.h>
+
+#define MGLAssertIsMainThread() NSAssert([[NSThread currentThread] isMainThread], @"-[%@ %@] must be accessed on the main thread, not %@", [self class], NSStringFromSelector(_cmd), [NSThread currentThread])