summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-05-16 21:28:49 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-06-11 11:37:23 -0700
commitf46328655e027bf490692fcde4aab770912aac8d (patch)
tree4be947bf81e7f42392aafe6874f4ded5e21e5ace /platform
parentcfee5aa8ef73b5bd2050bd68d584846192ebf0a2 (diff)
downloadqtlocation-mapboxgl-f46328655e027bf490692fcde4aab770912aac8d.tar.gz
Audited headers for nullability
Added some nullability qualifiers in method implementation selectors for consistency with declarations. The user dot view now has a non-zero size. Previously only its layer was sized properly. Also resolved some pedantic warnings about missing designated initializer overrides. Xcode 6.3 or above is now required for building this project.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLAccountManager.m2
-rw-r--r--platform/ios/MGLFileCache.h6
-rw-r--r--platform/ios/MGLMapView.mm35
-rw-r--r--platform/ios/MGLMapboxEvents.h8
-rw-r--r--platform/ios/MGLMapboxEvents.m6
-rw-r--r--platform/ios/MGLUserLocation.m7
-rw-r--r--platform/ios/MGLUserLocationAnnotationView.h12
-rw-r--r--platform/ios/MGLUserLocationAnnotationView.m17
-rw-r--r--platform/ios/MGLUserLocation_Private.h10
-rw-r--r--platform/ios/NSBundle+MGLAdditions.h6
-rw-r--r--platform/ios/NSString+MGLAdditions.h8
-rw-r--r--platform/ios/NSString+MGLAdditions.m2
12 files changed, 83 insertions, 36 deletions
diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m
index 71987786c9..d391ea8818 100644
--- a/platform/ios/MGLAccountManager.m
+++ b/platform/ios/MGLAccountManager.m
@@ -1,5 +1,3 @@
-#import <Foundation/Foundation.h>
-
#import "MGLAccountManager_Private.h"
#import "MGLMapboxEvents.h"
#import "NSProcessInfo+MGLAdditions.h"
diff --git a/platform/ios/MGLFileCache.h b/platform/ios/MGLFileCache.h
index 5e9f37fe2d..082cec69a3 100644
--- a/platform/ios/MGLFileCache.h
+++ b/platform/ios/MGLFileCache.h
@@ -1,10 +1,14 @@
-#import <Foundation/Foundation.h>
+#import "MGLTypes.h"
#include <mbgl/storage/sqlite_cache.hpp>
+NS_ASSUME_NONNULL_BEGIN
+
@interface MGLFileCache : NSObject
+ (mbgl::SQLiteCache *)obtainSharedCacheWithObject:(NSObject *)object;
+ (void)releaseSharedCacheForObject:(NSObject *)object;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index a517a4d26f..f9318f067b 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -75,7 +75,6 @@ CLLocationDegrees MGLDegreesFromRadians(CGFloat radians)
@property (nonatomic) UIPinchGestureRecognizer *pinch;
@property (nonatomic) UIRotationGestureRecognizer *rotate;
@property (nonatomic) UILongPressGestureRecognizer *quickZoom;
-@property (nonatomic) NSMutableArray *bundledStyleURLs;
@property (nonatomic) NSMapTable *annotationIDsByAnnotation;
@property (nonatomic) std::vector<uint32_t> annotationsNearbyLastTap;
@property (nonatomic, weak) id <MGLAnnotation> selectedAnnotation;
@@ -97,6 +96,8 @@ CLLocationDegrees MGLDegreesFromRadians(CGFloat radians)
mbgl::Map *_mbglMap;
MBGLView *_mbglView;
mbgl::DefaultFileSource *_mbglFileSource;
+
+ NSMutableArray *_bundledStyleURLs;
BOOL _isTargetingInterfaceBuilder;
CLLocationDegrees _pendingLatitude;
@@ -122,7 +123,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
return self;
}
-- (instancetype)initWithFrame:(CGRect)frame styleURL:(NSURL *)styleURL
+- (instancetype)initWithFrame:(CGRect)frame styleURL:(nullable NSURL *)styleURL
{
if (self = [super initWithFrame:frame])
{
@@ -132,7 +133,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
return self;
}
-- (instancetype)initWithCoder:(NSCoder *)decoder
+- (instancetype)initWithCoder:(nonnull NSCoder *)decoder
{
if (self = [super initWithCoder:decoder])
{
@@ -142,13 +143,13 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
return self;
}
-- (NSString *)accessToken
+- (nullable NSString *)accessToken
{
NSAssert(NO, @"-[MGLMapView accessToken] has been removed. Use +[MGLAccountManager accessToken] or get MGLMapboxAccessToken from the Info.plist.");
return nil;
}
-- (void)setAccessToken:(NSString *)accessToken
+- (void)setAccessToken:(nullable NSString *)accessToken
{
NSAssert(NO, @"-[MGLMapView setAccessToken:] has been replaced by +[MGLAccountManager setAccessToken:].\n\nIf you previously set this access token in a storyboard inspectable, select the MGLMapView in Interface Builder and delete the “accessToken” entry from the User Defined Runtime Attributes section of the Identity inspector. Then go to the Info.plist file and set MGLMapboxAccessToken to “%@”.", accessToken);
}
@@ -158,13 +159,14 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
return [NSSet setWithObject:@"styleID"];
}
-- (NSURL *)styleURL
+- (nonnull NSURL *)styleURL
{
NSString *styleURLString = @(_mbglMap->getStyleURL().c_str()).mgl_stringOrNilIfEmpty;
+ NSAssert(styleURLString || _isTargetingInterfaceBuilder, @"Invalid style URL string %@", styleURLString);
return styleURLString ? [NSURL URLWithString:styleURLString] : nil;
}
-- (void)setStyleURL:(NSURL *)styleURL
+- (void)setStyleURL:(nullable NSURL *)styleURL
{
if (_isTargetingInterfaceBuilder) return;
@@ -422,7 +424,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
}
}
-- (void)setDelegate:(id<MGLMapViewDelegate>)delegate
+- (void)setDelegate:(nullable id<MGLMapViewDelegate>)delegate
{
if (_delegate == delegate) return;
@@ -1220,6 +1222,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
{
if ([self.delegate respondsToSelector:@selector(mapView:annotation:calloutAccessoryControlTapped:)])
{
+ NSAssert([tap.view isKindOfClass:[UIControl class]], @"Tapped view %@ is not a UIControl", tap.view);
[self.delegate mapView:self annotation:self.selectedAnnotation
calloutAccessoryControlTapped:(UIControl *)tap.view];
}
@@ -1477,7 +1480,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
[self setDirection:direction animated:NO];
}
-- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view
+- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(nullable UIView *)view
{
CGPoint convertedPoint = [self convertPoint:point fromView:view];
@@ -1488,7 +1491,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
return MGLLocationCoordinate2DFromLatLng(_mbglMap->latLngForPixel(mbgl::vec2<double>(convertedPoint.x, convertedPoint.y)));
}
-- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view
+- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(nullable UIView *)view
{
mbgl::vec2<double> pixel = _mbglMap->pixelForLatLng(MGLLatLngFromLocationCoordinate2D(coordinate));
@@ -1555,24 +1558,24 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
return [NSSet setWithObject:@"styleURL"];
}
-- (NSString *)styleID
+- (nullable NSString *)styleID
{
NSURL *styleURL = self.styleURL;
return [styleURL.scheme isEqualToString:@"mapbox"] ? styleURL.host.mgl_stringOrNilIfEmpty : nil;
}
-- (void)setStyleID:(NSString *)styleID
+- (void)setStyleID:(nullable NSString *)styleID
{
self.styleURL = styleID ? [NSURL URLWithString:[NSString stringWithFormat:@"mapbox://%@", styleID]] : nil;
}
-- (NSString *)mapID
+- (nullable NSString *)mapID
{
NSAssert(NO, @"-[MGLMapView mapID] has been renamed -[MGLMapView styleID].");
return nil;
}
-- (void)setMapID:(NSString *)mapID
+- (void)setMapID:(nullable NSString *)mapID
{
NSAssert(NO, @"-[MGLMapView setMapID:] has been renamed -[MGLMapView setStyleID:].\n\nIf you previously set this map ID in a storyboard inspectable, select the MGLMapView in Interface Builder and delete the “mapID” entry from the User Defined Runtime Attributes section of the Identity inspector. Then go to the Attributes inspector and enter “%@” into the “Style ID” field.", mapID);
}
@@ -1632,7 +1635,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
#pragma mark - Annotations -
-- (NSArray *)annotations
+- (nullable NSArray *)annotations
{
if ([_annotationIDsByAnnotation count])
{
@@ -1941,7 +1944,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
return [NSSet setWithObject:@"userLocationAnnotationView"];
}
-- (MGLUserLocation *)userLocation
+- (nullable MGLUserLocation *)userLocation
{
return self.userLocationAnnotationView.annotation;
}
diff --git a/platform/ios/MGLMapboxEvents.h b/platform/ios/MGLMapboxEvents.h
index 00de64a8b0..8ca0832910 100644
--- a/platform/ios/MGLMapboxEvents.h
+++ b/platform/ios/MGLMapboxEvents.h
@@ -1,4 +1,6 @@
-#import <Foundation/Foundation.h>
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
extern NSString *const MGLEventTypeAppUserTurnstile;
extern NSString *const MGLEventTypeMapLoad;
@@ -31,7 +33,7 @@ extern NSString *const MGLEventGestureRotateStart;
@interface MGLMapboxEvents : NSObject <NSURLSessionDelegate>
-+ (instancetype)sharedManager;
++ (nullable instancetype)sharedManager;
// You must call these methods from the main thread.
//
@@ -61,3 +63,5 @@ extern NSString *const MGLEventGestureRotateStart;
+ (void)validate;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m
index bf730af945..9125b56fdd 100644
--- a/platform/ios/MGLMapboxEvents.m
+++ b/platform/ios/MGLMapboxEvents.m
@@ -304,7 +304,7 @@ const NSTimeInterval MGLFlushInterval = 60;
// Can be called from any thread. Called implicitly from any
// public class convenience methods. May return nil if this feature is disabled.
//
-+ (instancetype)sharedManager {
++ (nullable instancetype)sharedManager {
if (NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) {
return nil;
}
@@ -597,7 +597,9 @@ const NSTimeInterval MGLFlushInterval = 60;
[request setHTTPBody:jsonData];
// Send non blocking HTTP Request to server
- NSURLSessionDataTask *task = [_session dataTaskWithRequest:request completionHandler: nil];
+ NSURLSessionDataTask *task = [_session dataTaskWithRequest:request completionHandler:^(__unused NSData * __nullable data, __unused NSURLResponse * __nullable response, __unused NSError * __nullable error)
+ {
+ }];
[task resume];
}
});
diff --git a/platform/ios/MGLUserLocation.m b/platform/ios/MGLUserLocation.m
index cdeae3a9ce..201e54605e 100644
--- a/platform/ios/MGLUserLocation.m
+++ b/platform/ios/MGLUserLocation.m
@@ -2,19 +2,24 @@
#import "MGLMapView.h"
+NS_ASSUME_NONNULL_BEGIN
+
@interface MGLUserLocation ()
@property (nonatomic, weak) MGLMapView *mapView;
@end
+NS_ASSUME_NONNULL_END
+
@implementation MGLUserLocation
-- (instancetype)init
+- (instancetype)initWithMapView:(MGLMapView *)mapView
{
if (self = [super init])
{
_location = [[CLLocation alloc] initWithLatitude:MAXFLOAT longitude:MAXFLOAT];
+ _mapView = mapView;
}
return self;
diff --git a/platform/ios/MGLUserLocationAnnotationView.h b/platform/ios/MGLUserLocationAnnotationView.h
index a9f3bb0a0e..1eb50b7740 100644
--- a/platform/ios/MGLUserLocationAnnotationView.h
+++ b/platform/ios/MGLUserLocationAnnotationView.h
@@ -1,17 +1,23 @@
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
@class MGLMapView;
@class MGLUserLocation;
-/** The MGLUserLocationAnnotationView class defines a specific type of annotation that identifies the user’s current location. You do not create instances of this class directly. Instead, you retrieve an existing MGLUserLocationAnnotationView object from the userLocation property of the map view displayed in your application. */
+/** View representing an MGLUserLocation on screen. */
@interface MGLUserLocationAnnotationView : UIView
@property (nonatomic, weak) MGLMapView *mapView;
@property (nonatomic) MGLUserLocation *annotation;
-@property (nonatomic, readonly) CALayer *haloLayer;
+@property (nonatomic, readonly, nullable) CALayer *haloLayer;
-- (instancetype)initInMapView:(MGLMapView *)mapView;
+- (instancetype)initInMapView:(MGLMapView *)mapView NS_DESIGNATED_INITIALIZER;
- (void)setupLayers;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/MGLUserLocationAnnotationView.m b/platform/ios/MGLUserLocationAnnotationView.m
index c130582d6f..67f360f68a 100644
--- a/platform/ios/MGLUserLocationAnnotationView.m
+++ b/platform/ios/MGLUserLocationAnnotationView.m
@@ -22,12 +22,17 @@ const CGFloat MGLTrackingDotRingWidth = 24.0;
CALayer *_dotLayer;
}
+- (instancetype)initWithFrame:(CGRect)frame
+{
+ NSAssert(NO, @"No containing map view specified. Call -initInMapView: instead.");
+ return self = [self init];
+}
+
- (instancetype)initInMapView:(MGLMapView *)mapView
{
- if (self = [super init])
+ if (self = [super initWithFrame:CGRectMake(0, 0, MGLTrackingDotRingWidth, MGLTrackingDotRingWidth)])
{
- self.annotation = [[MGLUserLocation alloc] init];
- self.annotation.mapView = mapView;
+ self.annotation = [[MGLUserLocation alloc] initWithMapView:mapView];
_mapView = mapView;
[self setupLayers];
self.accessibilityLabel = @"User location";
@@ -35,6 +40,12 @@ const CGFloat MGLTrackingDotRingWidth = 24.0;
return self;
}
+- (instancetype)initWithCoder:(NSCoder *)decoder
+{
+ MGLMapView *mapView = [decoder valueForKey:@"mapView"];
+ return [self initInMapView:mapView];
+}
+
- (void)setTintColor:(UIColor *)tintColor
{
UIImage *trackingDotHaloImage = [self trackingDotHaloImage];
diff --git a/platform/ios/MGLUserLocation_Private.h b/platform/ios/MGLUserLocation_Private.h
index 147e3b3530..892ddfa478 100644
--- a/platform/ios/MGLUserLocation_Private.h
+++ b/platform/ios/MGLUserLocation_Private.h
@@ -1,11 +1,17 @@
#import "MGLUserLocation.h"
+NS_ASSUME_NONNULL_BEGIN
+
@class MGLMapView;
@interface MGLUserLocation (Private)
@property (nonatomic, weak) MGLMapView *mapView;
-@property (nonatomic, readwrite) CLLocation *location;
-@property (nonatomic, readwrite) CLHeading *heading;
+@property (nonatomic, readwrite, nullable) CLLocation *location;
+@property (nonatomic, readwrite, nullable) CLHeading *heading;
+
+- (instancetype)initWithMapView:(MGLMapView *)mapView;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/NSBundle+MGLAdditions.h b/platform/ios/NSBundle+MGLAdditions.h
index 1fc0803b4d..0de96bf310 100644
--- a/platform/ios/NSBundle+MGLAdditions.h
+++ b/platform/ios/NSBundle+MGLAdditions.h
@@ -1,7 +1,11 @@
-#import <Foundation/Foundation.h>
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
@interface NSBundle (MGLAdditions)
+ (NSString *)mgl_resourceBundlePath;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/NSString+MGLAdditions.h b/platform/ios/NSString+MGLAdditions.h
index 913f1cacda..6359576c28 100644
--- a/platform/ios/NSString+MGLAdditions.h
+++ b/platform/ios/NSString+MGLAdditions.h
@@ -1,8 +1,12 @@
-#import <Foundation/Foundation.h>
+#import "MGLTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
@interface NSString (MGLAdditions)
/** Returns the receiver if non-empty or nil if empty. */
-- (NSString *)mgl_stringOrNilIfEmpty;
+- (nullable NSString *)mgl_stringOrNilIfEmpty;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/NSString+MGLAdditions.m b/platform/ios/NSString+MGLAdditions.m
index d80c34cef0..969886651b 100644
--- a/platform/ios/NSString+MGLAdditions.m
+++ b/platform/ios/NSString+MGLAdditions.m
@@ -2,7 +2,7 @@
@implementation NSString (MGLAdditions)
-- (NSString *)mgl_stringOrNilIfEmpty
+- (nullable NSString *)mgl_stringOrNilIfEmpty
{
return self.length ? self : nil;
}