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

Commit

Permalink
Use collection and box literals in ObjC code (#3960)
Browse files Browse the repository at this point in the history
Replaces the harder-to-read and more-error-prone
dictionaryWithObjectsAndKeys: and dictionaryWithObject:forKey: with
modern dictionary literals.

Also replaces numberWith*: with boxed literal syntax.
  • Loading branch information
stuartmorgan authored May 21, 2021
1 parent 387a4fa commit 7b47511
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 23 deletions.
12 changes: 6 additions & 6 deletions packages/camera/camera/ios/Classes/CameraPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -1169,12 +1169,12 @@ - (BOOL)setupWriterForPath:(NSString *)path {
acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
NSDictionary *audioOutputSettings = nil;
// Both type of audio inputs causes output video file to be corrupted.
audioOutputSettings = [NSDictionary
dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSData dataWithBytes:&acl length:sizeof(acl)],
AVChannelLayoutKey, nil];
audioOutputSettings = @{
AVFormatIDKey : [NSNumber numberWithInt:kAudioFormatMPEG4AAC],
AVSampleRateKey : [NSNumber numberWithFloat:44100.0],
AVNumberOfChannelsKey : [NSNumber numberWithInt:1],
AVChannelLayoutKey : [NSData dataWithBytes:&acl length:sizeof(acl)],
};
_audioWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio
outputSettings:audioOutputSettings];
_audioWriterInput.expectsMediaDataInRealTime = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSNumber* isCompassEnabled = @(_mapView.settings.compassButton);
result(isCompassEnabled);
} else if ([call.method isEqualToString:@"map#isMapToolbarEnabled"]) {
NSNumber* isMapToolbarEnabled = [NSNumber numberWithBool:NO];
NSNumber* isMapToolbarEnabled = @NO;
result(isMapToolbarEnabled);
} else if ([call.method isEqualToString:@"map#getMinMaxZoomLevels"]) {
NSArray* zoomLevels = @[ @(_mapView.minZoom), @(_mapView.maxZoom) ];
Expand All @@ -340,7 +340,7 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSNumber* isZoomGesturesEnabled = @(_mapView.settings.zoomGestures);
result(isZoomGesturesEnabled);
} else if ([call.method isEqualToString:@"map#isZoomControlsEnabled"]) {
NSNumber* isZoomControlsEnabled = [NSNumber numberWithBool:NO];
NSNumber* isZoomControlsEnabled = @NO;
result(isZoomControlsEnabled);
} else if ([call.method isEqualToString:@"map#isTiltGesturesEnabled"]) {
NSNumber* isTiltGesturesEnabled = @(_mapView.settings.tiltGestures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ + (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
(CFURLRef)[NSURL fileURLWithPath:path], kUTTypeGIF, gifInfo.images.count, NULL);

NSDictionary *frameProperties = [NSDictionary
dictionaryWithObject:[NSDictionary
dictionaryWithObject:[NSNumber numberWithFloat:gifInfo.interval]
forKey:(NSString *)kCGImagePropertyGIFDelayTime]
forKey:(NSString *)kCGImagePropertyGIFDictionary];
NSDictionary *frameProperties = @{
(__bridge NSString *)kCGImagePropertyGIFDictionary : @{
(__bridge NSString *)kCGImagePropertyGIFDelayTime : @(gifInfo.interval),
},
};

NSMutableDictionary *gifMetaProperties = [NSMutableDictionary dictionaryWithDictionary:metaData];
NSMutableDictionary *gifProperties =
Expand All @@ -111,7 +111,7 @@ + (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
gifProperties = [NSMutableDictionary dictionary];
}

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

CGImageDestinationSetProperties(destination, (CFDictionaryRef)gifMetaProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ - (NSNumber *)getDesiredImageQuality:(NSNumber *)imageQuality {
if (![imageQuality isKindOfClass:[NSNumber class]]) {
imageQuality = @1;
} else if (imageQuality.intValue < 0 || imageQuality.intValue > 100) {
imageQuality = [NSNumber numberWithInt:1];
imageQuality = @1;
} else {
imageQuality = @([imageQuality floatValue] / 100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
}

- (void)canMakePayments:(FlutterResult)result {
result([NSNumber numberWithBool:[SKPaymentQueue canMakePayments]]);
result(@([SKPaymentQueue canMakePayments]));
}

- (void)getPendingTransactions:(FlutterResult)result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)testCanMakePayments {
result = r;
}];
[self waitForExpectations:@[ expectation ] timeout:5];
XCTAssertEqual(result, [NSNumber numberWithBool:YES]);
XCTAssertEqual(result, @YES);
}

- (void)testGetProductResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
NSNumber *newValue =
change[NSKeyValueChangeNewKey] ?: 0; // newValue is anywhere between 0.0 and 1.0
int newValueAsInt = [newValue floatValue] * 100; // Anywhere between 0 and 100
[_methodChannel invokeMethod:@"onProgress"
arguments:@{@"progress" : [NSNumber numberWithInt:newValueAsInt]}];
[_methodChannel invokeMethod:@"onProgress" arguments:@{@"progress" : @(newValueAsInt)}];
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/webview_flutter/ios/Classes/FlutterWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ - (void)onLoadUrl:(FlutterMethodCall*)call result:(FlutterResult)result {

- (void)onCanGoBack:(FlutterMethodCall*)call result:(FlutterResult)result {
BOOL canGoBack = [_webView canGoBack];
result([NSNumber numberWithBool:canGoBack]);
result(@(canGoBack));
}

- (void)onCanGoForward:(FlutterMethodCall*)call result:(FlutterResult)result {
BOOL canGoForward = [_webView canGoForward];
result([NSNumber numberWithBool:canGoForward]);
result(@(canGoForward));
}

- (void)onGoBack:(FlutterMethodCall*)call result:(FlutterResult)result {
Expand Down Expand Up @@ -314,12 +314,12 @@ - (void)onScrollBy:(FlutterMethodCall*)call result:(FlutterResult)result {

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

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

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

0 comments on commit 7b47511

Please sign in to comment.