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

Commit 7b47511

Browse files
Use collection and box literals in ObjC code (#3960)
Replaces the harder-to-read and more-error-prone dictionaryWithObjectsAndKeys: and dictionaryWithObject:forKey: with modern dictionary literals. Also replaces numberWith*: with boxed literal syntax.
1 parent 387a4fa commit 7b47511

File tree

8 files changed

+22
-23
lines changed

8 files changed

+22
-23
lines changed

packages/camera/camera/ios/Classes/CameraPlugin.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -1169,12 +1169,12 @@ - (BOOL)setupWriterForPath:(NSString *)path {
11691169
acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
11701170
NSDictionary *audioOutputSettings = nil;
11711171
// Both type of audio inputs causes output video file to be corrupted.
1172-
audioOutputSettings = [NSDictionary
1173-
dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,
1174-
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
1175-
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
1176-
[NSData dataWithBytes:&acl length:sizeof(acl)],
1177-
AVChannelLayoutKey, nil];
1172+
audioOutputSettings = @{
1173+
AVFormatIDKey : [NSNumber numberWithInt:kAudioFormatMPEG4AAC],
1174+
AVSampleRateKey : [NSNumber numberWithFloat:44100.0],
1175+
AVNumberOfChannelsKey : [NSNumber numberWithInt:1],
1176+
AVChannelLayoutKey : [NSData dataWithBytes:&acl length:sizeof(acl)],
1177+
};
11781178
_audioWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio
11791179
outputSettings:audioOutputSettings];
11801180
_audioWriterInput.expectsMediaDataInRealTime = YES;

packages/google_maps_flutter/google_maps_flutter/ios/Classes/GoogleMapController.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
329329
NSNumber* isCompassEnabled = @(_mapView.settings.compassButton);
330330
result(isCompassEnabled);
331331
} else if ([call.method isEqualToString:@"map#isMapToolbarEnabled"]) {
332-
NSNumber* isMapToolbarEnabled = [NSNumber numberWithBool:NO];
332+
NSNumber* isMapToolbarEnabled = @NO;
333333
result(isMapToolbarEnabled);
334334
} else if ([call.method isEqualToString:@"map#getMinMaxZoomLevels"]) {
335335
NSArray* zoomLevels = @[ @(_mapView.minZoom), @(_mapView.maxZoom) ];
@@ -340,7 +340,7 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
340340
NSNumber* isZoomGesturesEnabled = @(_mapView.settings.zoomGestures);
341341
result(isZoomGesturesEnabled);
342342
} else if ([call.method isEqualToString:@"map#isZoomControlsEnabled"]) {
343-
NSNumber* isZoomControlsEnabled = [NSNumber numberWithBool:NO];
343+
NSNumber* isZoomControlsEnabled = @NO;
344344
result(isZoomControlsEnabled);
345345
} else if ([call.method isEqualToString:@"map#isTiltGesturesEnabled"]) {
346346
NSNumber* isTiltGesturesEnabled = @(_mapView.settings.tiltGestures);

packages/image_picker/image_picker/ios/Classes/FLTImagePickerPhotoAssetUtil.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ + (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
9898
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
9999
(CFURLRef)[NSURL fileURLWithPath:path], kUTTypeGIF, gifInfo.images.count, NULL);
100100

101-
NSDictionary *frameProperties = [NSDictionary
102-
dictionaryWithObject:[NSDictionary
103-
dictionaryWithObject:[NSNumber numberWithFloat:gifInfo.interval]
104-
forKey:(NSString *)kCGImagePropertyGIFDelayTime]
105-
forKey:(NSString *)kCGImagePropertyGIFDictionary];
101+
NSDictionary *frameProperties = @{
102+
(__bridge NSString *)kCGImagePropertyGIFDictionary : @{
103+
(__bridge NSString *)kCGImagePropertyGIFDelayTime : @(gifInfo.interval),
104+
},
105+
};
106106

107107
NSMutableDictionary *gifMetaProperties = [NSMutableDictionary dictionaryWithDictionary:metaData];
108108
NSMutableDictionary *gifProperties =
@@ -111,7 +111,7 @@ + (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
111111
gifProperties = [NSMutableDictionary dictionary];
112112
}
113113

114-
gifProperties[(NSString *)kCGImagePropertyGIFLoopCount] = [NSNumber numberWithFloat:0];
114+
gifProperties[(__bridge NSString *)kCGImagePropertyGIFLoopCount] = @0;
115115

116116
CGImageDestinationSetProperties(destination, (CFDictionaryRef)gifMetaProperties);
117117

packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ - (NSNumber *)getDesiredImageQuality:(NSNumber *)imageQuality {
348348
if (![imageQuality isKindOfClass:[NSNumber class]]) {
349349
imageQuality = @1;
350350
} else if (imageQuality.intValue < 0 || imageQuality.intValue > 100) {
351-
imageQuality = [NSNumber numberWithInt:1];
351+
imageQuality = @1;
352352
} else {
353353
imageQuality = @([imageQuality floatValue] / 100);
354354
}

packages/in_app_purchase/in_app_purchase_ios/ios/Classes/InAppPurchasePlugin.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
106106
}
107107

108108
- (void)canMakePayments:(FlutterResult)result {
109-
result([NSNumber numberWithBool:[SKPaymentQueue canMakePayments]]);
109+
result(@([SKPaymentQueue canMakePayments]));
110110
}
111111

112112
- (void)getPendingTransactions:(FlutterResult)result {

packages/in_app_purchase/in_app_purchase_ios/ios/Tests/InAppPurchasePluginTest.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ - (void)testCanMakePayments {
5151
result = r;
5252
}];
5353
[self waitForExpectations:@[ expectation ] timeout:5];
54-
XCTAssertEqual(result, [NSNumber numberWithBool:YES]);
54+
XCTAssertEqual(result, @YES);
5555
}
5656

5757
- (void)testGetProductResponse {

packages/webview_flutter/ios/Classes/FLTWKProgressionDelegate.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
3434
NSNumber *newValue =
3535
change[NSKeyValueChangeNewKey] ?: 0; // newValue is anywhere between 0.0 and 1.0
3636
int newValueAsInt = [newValue floatValue] * 100; // Anywhere between 0 and 100
37-
[_methodChannel invokeMethod:@"onProgress"
38-
arguments:@{@"progress" : [NSNumber numberWithInt:newValueAsInt]}];
37+
[_methodChannel invokeMethod:@"onProgress" arguments:@{@"progress" : @(newValueAsInt)}];
3938
}
4039
}
4140

packages/webview_flutter/ios/Classes/FlutterWebView.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ - (void)onLoadUrl:(FlutterMethodCall*)call result:(FlutterResult)result {
194194

195195
- (void)onCanGoBack:(FlutterMethodCall*)call result:(FlutterResult)result {
196196
BOOL canGoBack = [_webView canGoBack];
197-
result([NSNumber numberWithBool:canGoBack]);
197+
result(@(canGoBack));
198198
}
199199

200200
- (void)onCanGoForward:(FlutterMethodCall*)call result:(FlutterResult)result {
201201
BOOL canGoForward = [_webView canGoForward];
202-
result([NSNumber numberWithBool:canGoForward]);
202+
result(@(canGoForward));
203203
}
204204

205205
- (void)onGoBack:(FlutterMethodCall*)call result:(FlutterResult)result {
@@ -314,12 +314,12 @@ - (void)onScrollBy:(FlutterMethodCall*)call result:(FlutterResult)result {
314314

315315
- (void)getScrollX:(FlutterMethodCall*)call result:(FlutterResult)result {
316316
int offsetX = _webView.scrollView.contentOffset.x;
317-
result([NSNumber numberWithInt:offsetX]);
317+
result(@(offsetX));
318318
}
319319

320320
- (void)getScrollY:(FlutterMethodCall*)call result:(FlutterResult)result {
321321
int offsetY = _webView.scrollView.contentOffset.y;
322-
result([NSNumber numberWithInt:offsetY]);
322+
result(@(offsetY));
323323
}
324324

325325
// Returns nil when successful, or an error message when one or more keys are unknown.

0 commit comments

Comments
 (0)