Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 9dd8d26

Browse files
committed
Merge pull request #1653 from mapbox/1ec5-init-unfail
Make init methods unfailable
2 parents ceef4d3 + 86dd0e9 commit 9dd8d26

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

include/mbgl/ios/MGLMapView.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ IB_DESIGNABLE
2222

2323
/** Initializes and returns a newly allocated map view with the specified frame and the default style.
2424
* @param frame The frame for the view, measured in points.
25-
* @return An initialized map view or `nil` if the map view couldn’t be created. */
25+
* @return An initialized map view. */
2626
- (instancetype)initWithFrame:(CGRect)frame;
2727
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken __attribute__((unavailable("Use -initWithFrame:. Set MGLMapboxAccessToken in the Info.plist or call +[MGLAccountManager setAccessToken:].")));
2828

2929
/** Initializes and returns a newly allocated map view with the specified frame and style URL.
3030
* @param frame The frame for the view, measured in points.
3131
* @param styleURL The map style URL to use. Can be either an HTTP/HTTPS URL or a Mapbox map ID style URL (`mapbox://<user.style>`).
32-
* @return An initialized map view or `nil` if the map view couldn’t be created. */
32+
* @return An initialized map view. */
3333
- (instancetype)initWithFrame:(CGRect)frame styleURL:(NSURL *)styleURL;
3434
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken styleURL:(NSURL *)styleURL __attribute__((unavailable("Use -initWithFrame:styleURL:. Set MGLMapboxAccessToken in the Info.plist or call +[MGLAccountManager setAccessToken:].")));
3535

platform/ios/MGLMapView.mm

+11-28
Original file line numberDiff line numberDiff line change
@@ -114,41 +114,32 @@ @implementation MGLMapView
114114

115115
- (instancetype)initWithFrame:(CGRect)frame
116116
{
117-
self = [super initWithFrame:frame];
118-
119-
if (self && [self commonInit])
117+
if (self = [super initWithFrame:frame])
120118
{
119+
[self commonInit];
121120
self.styleURL = nil;
122-
return self;
123121
}
124-
125-
return nil;
122+
return self;
126123
}
127124

128125
- (instancetype)initWithFrame:(CGRect)frame styleURL:(NSURL *)styleURL
129126
{
130-
self = [super initWithFrame:frame];
131-
132-
if (self && [self commonInit])
127+
if (self = [super initWithFrame:frame])
133128
{
129+
[self commonInit];
134130
self.styleURL = styleURL;
135-
return self;
136131
}
137-
138-
return nil;
132+
return self;
139133
}
140134

141135
- (instancetype)initWithCoder:(NSCoder *)decoder
142136
{
143-
self = [super initWithCoder:decoder];
144-
145-
if (self && [self commonInit])
137+
if (self = [super initWithCoder:decoder])
146138
{
139+
[self commonInit];
147140
self.styleURL = nil;
148-
return self;
149141
}
150-
151-
return nil;
142+
return self;
152143
}
153144

154145
- (NSString *)accessToken
@@ -193,20 +184,14 @@ - (void)setStyleURL:(NSURL *)styleURL
193184
_mbglMap->setStyleURL([[styleURL absoluteString] UTF8String]);
194185
}
195186

196-
- (BOOL)commonInit
187+
- (void)commonInit
197188
{
198189
_isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent;
199190

200191
// create context
201192
//
202193
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
203-
204-
if ( ! _context)
205-
{
206-
mbgl::Log::Error(mbgl::Event::Setup, "failed to create OpenGL ES context");
207-
208-
return NO;
209-
}
194+
NSAssert(_context, @"Failed to create OpenGL ES context.");
210195

211196
// setup accessibility
212197
//
@@ -394,8 +379,6 @@ - (BOOL)commonInit
394379
MGLEventKeyZoomLevel: @(zoom),
395380
MGLEventKeyPushEnabled: @([MGLMapboxEvents checkPushEnabled])
396381
}];
397-
398-
return YES;
399382
}
400383

401384
-(void)reachabilityChanged:(NSNotification*)notification

0 commit comments

Comments
 (0)