diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2015-04-20 09:58:05 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2015-04-20 09:58:05 -0700 |
commit | 2ec09a663f89a41ebe083a56c6a6944cc8b9293d (patch) | |
tree | 9e19726d9cd2a360afa2c6b960e2cdfacb3c065d | |
parent | 0bb2e05063436202cbd5e657f5cf87a4819da397 (diff) | |
download | qtlocation-mapboxgl-2ec09a663f89a41ebe083a56c6a6944cc8b9293d.tar.gz |
Use `strongSelf` inside blocks
It’d be pointless to create a `strongSelf` but not use it; `weakSelf` isn’t guaranteed to exist past that point.
-rw-r--r-- | platform/ios/MGLMapboxEvents.m | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 149d90904f..e7a0702abf 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -50,7 +50,7 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // from within a single thread use underscore syntax. // // All captures of `self` from within asynchronous -// dispatches will use a `weakSelf` to avoid cyclical +// dispatches will use a `strongSelf` to avoid cyclical // strong references. // @@ -293,35 +293,35 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // mapbox-events stock attributes [evt setObject:event forKey:@"event"]; [evt setObject:@(1) forKey:@"version"]; - [evt setObject:[weakSelf.rfc3339DateFormatter stringFromDate:[NSDate date]] forKey:@"created"]; - [evt setObject:weakSelf.instanceID forKey:@"instance"]; - [evt setObject:weakSelf.advertiserId forKey:@"advertiserId"]; - [evt setObject:weakSelf.vendorId forKey:@"vendorId"]; - [evt setObject:weakSelf.appBundleId forKeyedSubscript:@"appBundleId"]; + [evt setObject:[strongSelf.rfc3339DateFormatter stringFromDate:[NSDate date]] forKey:@"created"]; + [evt setObject:strongSelf.instanceID forKey:@"instance"]; + [evt setObject:strongSelf.advertiserId forKey:@"advertiserId"]; + [evt setObject:strongSelf.vendorId forKey:@"vendorId"]; + [evt setObject:strongSelf.appBundleId forKeyedSubscript:@"appBundleId"]; // mapbox-events-ios stock attributes - [evt setValue:weakSelf.model forKey:@"model"]; - [evt setValue:weakSelf.iOSVersion forKey:@"operatingSystem"]; - [evt setValue:[weakSelf getDeviceOrientation] forKey:@"orientation"]; + [evt setValue:strongSelf.model forKey:@"model"]; + [evt setValue:strongSelf.iOSVersion forKey:@"operatingSystem"]; + [evt setValue:[strongSelf getDeviceOrientation] forKey:@"orientation"]; [evt setValue:@(100 * [UIDevice currentDevice].batteryLevel) forKey:@"batteryLevel"]; - [evt setValue:@(weakSelf.scale) forKey:@"resolution"]; - [evt setValue:weakSelf.carrier forKey:@"carrier"]; + [evt setValue:@(strongSelf.scale) forKey:@"resolution"]; + [evt setValue:strongSelf.carrier forKey:@"carrier"]; - NSString *cell = [weakSelf getCurrentCellularNetworkConnectionType]; + NSString *cell = [strongSelf getCurrentCellularNetworkConnectionType]; if (cell) { [evt setValue:cell forKey:@"cellularNetworkType"]; } else { [evt setObject:[NSNull null] forKey:@"cellularNetworkType"]; } - NSString *wifi = [weakSelf getWifiNetworkName]; + NSString *wifi = [strongSelf getWifiNetworkName]; if (wifi) { [evt setValue:wifi forKey:@"wifi"]; } else { [evt setObject:[NSNull null] forKey:@"wifi"]; } - [evt setValue:@([weakSelf getContentSizeScale]) forKey:@"accessibilityFontScale"]; + [evt setValue:@([strongSelf getContentSizeScale]) forKey:@"accessibilityFontScale"]; // Make Immutable Version NSDictionary *finalEvent = [NSDictionary dictionaryWithDictionary:evt]; @@ -330,12 +330,12 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; [_eventQueue addObject:finalEvent]; // Has Flush Limit Been Reached? - if (_eventQueue.count >= weakSelf.flushAt) { - [weakSelf flush]; + if (_eventQueue.count >= strongSelf.flushAt) { + [strongSelf flush]; } // Reset Timer (Initial Starting of Timer after first event is pushed) - [weakSelf startTimer]; + [strongSelf startTimer]; }); } @@ -358,8 +358,8 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; __block NSArray *events; - NSUInteger upper = weakSelf.flushAt; - if (weakSelf.flushAt > [_eventQueue count]) { + NSUInteger upper = strongSelf.flushAt; + if (strongSelf.flushAt > [_eventQueue count]) { if ([_eventQueue count] == 0) { return; } @@ -374,7 +374,7 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; [_eventQueue removeObjectsInRange:theRange]; // Send Array of Events to Server - [weakSelf postEvents:events]; + [strongSelf postEvents:events]; }); } @@ -389,9 +389,9 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; if ( ! strongSelf) return; // Setup URL Request - NSString *url = [NSString stringWithFormat:@"%@/events/v1?access_token=%@", MGLMapboxEventsAPIBase, weakSelf.token]; + NSString *url = [NSString stringWithFormat:@"%@/events/v1?access_token=%@", MGLMapboxEventsAPIBase, strongSelf.token]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]]; - [request setValue:[weakSelf getUserAgent] forHTTPHeaderField:@"User-Agent"]; + [request setValue:[strongSelf getUserAgent] forHTTPHeaderField:@"User-Agent"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setHTTPMethod:@"POST"]; |