Skip to content

Commit

Permalink
Ran Convert > To Modern Objective C Syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Aug 25, 2015
1 parent a57353b commit 88e0bbc
Show file tree
Hide file tree
Showing 80 changed files with 247 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)setUp
RCTAssert(NO, @"Tests should be run on 32-bit device simulators (e.g. iPhone 5)");
#endif

NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
NSOperatingSystemVersion version = [NSProcessInfo processInfo].operatingSystemVersion;
RCTAssert(version.majorVersion == 8 || version.minorVersion >= 3, @"Tests should be run on iOS 8.3+, found %zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion);
_runner = RCTInitRunnerForApp(@"Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp", nil);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void)setUp
// Register 20 views to use in the tests
for (NSInteger i = 1; i <= 20; i++) {
UIView *registeredView = [UIView new];
[registeredView setReactTag:@(i)];
registeredView.reactTag = @(i);
_uiManager.viewRegistry[i] = registeredView;
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ - (void)testManagingChildrenToRemoveViews

NSArray *removeAtIndices = @[@0, @4, @8, @12, @16];
for (NSNumber *index in removeAtIndices) {
NSNumber *reactTag = @([index integerValue] + 2);
NSNumber *reactTag = @(index.integerValue + 2);
[removedViews addObject:_uiManager.viewRegistry[reactTag]];
}
for (NSInteger i = 2; i < 20; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (void)setUp
RCTAssert(NO, @"Tests should be run on 32-bit device simulators (e.g. iPhone 5)");
#endif

NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
NSOperatingSystemVersion version = [NSProcessInfo processInfo].operatingSystemVersion;
RCTAssert(version.majorVersion == 8 || version.minorVersion >= 3, @"Snapshot tests should be run on iOS 8.3+, found %zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion);
_runner = RCTInitRunnerForApp(@"Examples/UIExplorer/UIExplorerApp.ios", nil);
_runner.recordMode = NO;
Expand Down
4 changes: 2 additions & 2 deletions Examples/UIExplorer/UIExplorerUnitTests/RCTUIManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (void)setUp
// Register 20 views to use in the tests
for (NSInteger i = 1; i <= 20; i++) {
UIView *registeredView = [UIView new];
[registeredView setReactTag:@(i)];
registeredView.reactTag = @(i);
_uiManager.viewRegistry[i] = registeredView;
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ - (void)testManagingChildrenToRemoveViews

NSArray *removeAtIndices = @[@0, @4, @8, @12, @16];
for (NSNumber *index in removeAtIndices) {
NSNumber *reactTag = @([index integerValue] + 2);
NSNumber *reactTag = @(index.integerValue + 2);
[removedViews addObject:_uiManager.viewRegistry[reactTag]];
}
for (NSInteger i = 2; i < 20; i++) {
Expand Down
8 changes: 4 additions & 4 deletions Libraries/ActionSheetIOS/RCTActionSheetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (dispatch_queue_t)methodQueue

_callbacks[RCTKeyForInstance(actionSheet)] = successCallback;

UIWindow *appWindow = [[[UIApplication sharedApplication] delegate] window];
UIWindow *appWindow = [UIApplication sharedApplication].delegate.window;
if (appWindow == nil) {
RCTLogError(@"Tried to display action sheet but there is no application window. options: %@", options);
return;
Expand All @@ -81,12 +81,12 @@ - (dispatch_queue_t)methodQueue
if (URL) {
[items addObject:URL];
}
if ([items count] == 0) {
if (items.count == 0) {
failureCallback(@[@"No `url` or `message` to share"]);
return;
}
UIActivityViewController *share = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
UIViewController *ctrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
UIViewController *ctrl = [UIApplication sharedApplication].delegate.window.rootViewController;

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0

Expand Down Expand Up @@ -126,7 +126,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
RCTLogWarn(@"No callback registered for action sheet: %@", actionSheet.title);
}

[[[[UIApplication sharedApplication] delegate] window] makeKeyWindow];
[[UIApplication sharedApplication].delegate.window makeKeyWindow];
}

#pragma mark Private
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Geolocation/RCTLocationObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ - (void)timeout:(NSTimer *)timer
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// Create event
CLLocation *location = [locations lastObject];
CLLocation *location = locations.lastObject;
_lastLocationEvent = @{
@"coords": @{
@"latitude": @(location.coordinate.latitude),
Expand Down
12 changes: 6 additions & 6 deletions Libraries/Image/RCTCameraRollManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ @implementation RCTCameraRollManager
errorCallback(loadError);
return;
}
[_bridge.assetsLibrary writeImageToSavedPhotosAlbum:[loadedImage CGImage] metadata:nil completionBlock:^(NSURL *assetURL, NSError *saveError) {
[_bridge.assetsLibrary writeImageToSavedPhotosAlbum:loadedImage.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *saveError) {
if (saveError) {
RCTLogWarn(@"Error saving cropped image: %@", saveError);
errorCallback(saveError);
} else {
successCallback(@[[assetURL absoluteString]]);
successCallback(@[assetURL.absoluteString]);
}
}];
}];
}

- (void)callCallback:(RCTResponseSenderBlock)callback withAssets:(NSArray *)assets hasNextPage:(BOOL)hasNextPage
{
if (![assets count]) {
if (!assets.count) {
callback(@[@{
@"edges": assets,
@"page_info": @{
Expand Down Expand Up @@ -109,14 +109,14 @@ - (void)callCallback:(RCTResponseSenderBlock)callback withAssets:(NSArray *)asse

[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stopAssets) {
if (result) {
NSString *uri = [(NSURL *)[result valueForProperty:ALAssetPropertyAssetURL] absoluteString];
NSString *uri = ((NSURL *)[result valueForProperty:ALAssetPropertyAssetURL]).absoluteString;
if (afterCursor && !foundAfter) {
if ([afterCursor isEqualToString:uri]) {
foundAfter = YES;
}
return; // Skip until we get to the first one
}
if (first == [assets count]) {
if (first == assets.count) {
*stopAssets = YES;
*stopGroups = YES;
hasNextPage = YES;
Expand All @@ -138,7 +138,7 @@ - (void)callCallback:(RCTResponseSenderBlock)callback withAssets:(NSArray *)asse
@"width": @(dimensions.width),
@"isStored": @YES,
},
@"timestamp": @([date timeIntervalSince1970]),
@"timestamp": @(date.timeIntervalSince1970),
@"location": loc ?
@{
@"latitude": @(loc.coordinate.latitude),
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/RCTGIFImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
return nil;
}

if (![URL isFileURL]) {
if (!URL.fileURL) {
RCTLogError(@"Loading remote image URLs synchronously is a really bad idea.");
return nil;
}
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ - (RCTImageLoaderCancellationBlock)loadImageWithTag:(NSString *)imageTag
// The 'ph://' prefix is used by FBMediaKit to differentiate between
// assets-library. It is prepended to the local ID so that it is in the
// form of an, NSURL which is what assets-library uses.
NSString *phAssetID = [imageTag substringFromIndex:[@"ph://" length]];
NSString *phAssetID = [imageTag substringFromIndex:@"ph://".length];
PHFetchResult *results = [PHAsset fetchAssetsWithLocalIdentifiers:@[phAssetID] options:nil];
if (results.count == 0) {
NSString *errorText = [NSString stringWithFormat:@"Failed to fetch PHAsset with local identifier %@ with no error message.", phAssetID];
Expand All @@ -179,7 +179,7 @@ - (RCTImageLoaderCancellationBlock)loadImageWithTag:(NSString *)imageTag
return ^{};
}

PHAsset *asset = [results firstObject];
PHAsset *asset = results.firstObject;

PHImageRequestOptions *imageOptions = [PHImageRequestOptions new];

Expand Down
8 changes: 4 additions & 4 deletions Libraries/Image/RCTImagePickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (instancetype)init
successCallback:(RCTResponseSenderBlock)callback
cancelCallback:(RCTResponseSenderBlock)cancelCallback)
{
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = keyWindow.rootViewController;

UIImagePickerController *imagePicker = [UIImagePickerController new];
Expand All @@ -75,7 +75,7 @@ - (instancetype)init
successCallback:(RCTResponseSenderBlock)callback
cancelCallback:(RCTResponseSenderBlock)cancelCallback)
{
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = keyWindow.rootViewController;

UIImagePickerController *imagePicker = [UIImagePickerController new];
Expand Down Expand Up @@ -109,7 +109,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker
[_pickerCallbacks removeObjectAtIndex:index];
[_pickerCancelCallbacks removeObjectAtIndex:index];

UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = keyWindow.rootViewController;
[rootViewController dismissViewControllerAnimated:YES completion:nil];

Expand All @@ -125,7 +125,7 @@ - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
[_pickerCallbacks removeObjectAtIndex:index];
[_pickerCancelCallbacks removeObjectAtIndex:index];

UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = keyWindow.rootViewController;
[rootViewController dismissViewControllerAnimated:YES completion:nil];

Expand Down
4 changes: 2 additions & 2 deletions Libraries/Image/RCTImageRequestHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ @implementation RCTImageRequestHandler

- (BOOL)canHandleRequest:(NSURLRequest *)request
{
return [@[@"assets-library", @"ph"] containsObject:[request.URL.scheme lowercaseString]];
return [@[@"assets-library", @"ph"] containsObject:request.URL.scheme.lowercaseString];
}

- (id)sendRequest:(NSURLRequest *)request
withDelegate:(id<RCTURLRequestDelegate>)delegate
{
NSString *URLString = [request.URL absoluteString];
NSString *URLString = request.URL.absoluteString;

__block RCTImageLoaderCancellationBlock requestToken = nil;
requestToken = [_bridge.imageLoader loadImageWithTag:URLString callback:^(NSError *error, UIImage *image) {
Expand Down
8 changes: 4 additions & 4 deletions Libraries/Image/RCTImageStoreManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ @implementation RCTImageStoreManager

RCT_EXPORT_MODULE()

- (id)init
- (instancetype)init
{
if ((self = [super init])) {

Expand All @@ -34,7 +34,7 @@ - (id)init
- (NSString *)storeImage:(UIImage *)image
{
RCTAssertMainThread();
NSString *tag = [NSString stringWithFormat:@"rct-image-store://%tu", [_store count]];
NSString *tag = [NSString stringWithFormat:@"rct-image-store://%tu", _store.count];
_store[tag] = image;
return tag;
}
Expand Down Expand Up @@ -101,13 +101,13 @@ - (void)getImageForTag:(NSString *)imageTag withBlock:(void (^)(UIImage *image))

- (BOOL)canHandleRequest:(NSURLRequest *)request
{
return [@[@"rct-image-store"] containsObject:[request.URL.scheme lowercaseString]];
return [@[@"rct-image-store"] containsObject:request.URL.scheme.lowercaseString];
}

- (id)sendRequest:(NSURLRequest *)request
withDelegate:(id<RCTURLRequestDelegate>)delegate
{
NSString *imageTag = [request.URL absoluteString];
NSString *imageTag = request.URL.absoluteString;
[self getImageForTag:imageTag withBlock:^(UIImage *image) {
if (!image) {
NSError *error = RCTErrorWithMessage([NSString stringWithFormat:@"Invalid imageTag: %@", imageTag]);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/RCTImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
return self;
}

RCT_NOT_IMPLEMENTED(-init)
RCT_NOT_IMPLEMENTED(- (instancetype)init)

- (void)updateImage
{
Expand Down
6 changes: 3 additions & 3 deletions Libraries/LinkingIOS/RCTLinkingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ + (BOOL)application:(UIApplication *)application
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
NSDictionary *payload = @{@"url": [URL absoluteString]};
NSDictionary *payload = @{@"url": URL.absoluteString};
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
object:self
userInfo:payload];
Expand All @@ -52,7 +52,7 @@ + (BOOL)application:(UIApplication *)application
- (void)handleOpenURLNotification:(NSNotification *)notification
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"openURL"
body:[notification userInfo]];
body:notification.userInfo];
}

RCT_EXPORT_METHOD(openURL:(NSURL *)URL)
Expand All @@ -72,7 +72,7 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
- (NSDictionary *)constantsToExport
{
NSURL *initialURL = _bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
return @{@"initialURL": RCTNullIfNil([initialURL absoluteString])};
return @{@"initialURL": RCTNullIfNil(initialURL.absoluteString)};
}

@end
2 changes: 1 addition & 1 deletion Libraries/Network/RCTDownloadTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)invalidate
_uploadProgressBlock = nil;
}

RCT_NOT_IMPLEMENTED(-init)
RCT_NOT_IMPLEMENTED(- (instancetype)init)

- (void)cancel
{
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Network/RCTHTTPRequestHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (BOOL)isValid

- (BOOL)canHandleRequest:(NSURLRequest *)request
{
return [@[@"http", @"https", @"file"] containsObject:[request.URL.scheme lowercaseString]];
return [@[@"http", @"https", @"file"] containsObject:request.URL.scheme.lowercaseString];
}

- (NSURLSessionDataTask *)sendRequest:(NSURLRequest *)request
Expand Down
8 changes: 4 additions & 4 deletions Libraries/Network/RCTNetworking.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ - (RCTURLRequestCancellationBlock)handleResult:(NSDictionary *)result
NSMutableDictionary *headers = [parts[0][@"headers"] mutableCopy];
NSString *partContentType = result[@"contentType"];
if (partContentType != nil) {
[headers setObject:partContentType forKey:@"content-type"];
headers[@"content-type"] = partContentType;
}
[headers enumerateKeysAndObjectsUsingBlock:^(NSString *parameterKey, NSString *parameterValue, BOOL *stop) {
[multipartBody appendData:[[NSString stringWithFormat:@"%@: %@\r\n", parameterKey, parameterValue]
Expand Down Expand Up @@ -142,7 +142,7 @@ - (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query
{
NSURL *URL = [RCTConvert NSURL:query[@"url"]]; // this is marked as nullable in JS, but should not be null
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = [[RCTConvert NSString:RCTNilIfNull(query[@"method"])] uppercaseString] ?: @"GET";
request.HTTPMethod = [RCTConvert NSString:RCTNilIfNull(query[@"method"])].uppercaseString ?: @"GET";
request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]];

NSDictionary *data = [RCTConvert NSDictionary:RCTNilIfNull(query[@"data"])];
Expand All @@ -161,7 +161,7 @@ - (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query
// Gzip the request body
if ([request.allHTTPHeaderFields[@"Content-Encoding"] isEqualToString:@"gzip"]) {
request.HTTPBody = RCTGzipData(request.HTTPBody, -1 /* default */);
[request setValue:[@(request.HTTPBody.length) description] forHTTPHeaderField:@"Content-Length"];
[request setValue:(@(request.HTTPBody.length)).description forHTTPHeaderField:@"Content-Length"];
}

block(request);
Expand Down Expand Up @@ -195,7 +195,7 @@ - (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query
return NSOrderedSame;
}
}];
id<RCTURLRequestHandler> handler = [handlers lastObject];
id<RCTURLRequestHandler> handler = handlers.lastObject;
if (!handler) {
RCTLogError(@"No suitable request handler found for %@", request.URL);
}
Expand Down
6 changes: 3 additions & 3 deletions Libraries/PushNotificationIOS/RCTPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ + (void)application:(__unused UIApplication *)application didReceiveRemoteNotifi
- (void)handleRemoteNotificationReceived:(NSNotification *)notification
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"remoteNotificationReceived"
body:[notification userInfo]];
body:notification.userInfo];
}

- (void)handleRemoteNotificationsRegistered:(NSNotification *)notification
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"remoteNotificationsRegistered"
body:[notification userInfo]];
body:notification.userInfo];
}

/**
Expand Down Expand Up @@ -175,7 +175,7 @@ - (void)handleRemoteNotificationsRegistered:(NSNotification *)notification
{
NSUInteger types = 0;
if ([UIApplication instancesRespondToSelector:@selector(currentUserNotificationSettings)]) {
types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;
} else {

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
Expand Down
2 changes: 1 addition & 1 deletion Libraries/RCTTest/FBSnapshotTestCase/UIImage+Compare.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ - (BOOL)compareWithImage:(UIImage *)image
(CGBitmapInfo)kCGImageAlphaPremultipliedLast
);

CGFloat scaleFactor = [[UIScreen mainScreen] scale];
CGFloat scaleFactor = [UIScreen mainScreen].scale;
CGContextScaleCTM(referenceImageContext, scaleFactor, scaleFactor);
CGContextScaleCTM(imageContext, scaleFactor, scaleFactor);

Expand Down
2 changes: 1 addition & 1 deletion Libraries/RCTTest/RCTTestModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (instancetype)init
[_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {

NSString *testName = NSStringFromSelector(_testSelector);
_snapshotCounter[testName] = [@([_snapshotCounter[testName] integerValue] + 1) stringValue];
_snapshotCounter[testName] = (@([_snapshotCounter[testName] integerValue] + 1)).stringValue;

NSError *error = nil;
BOOL success = [_controller compareSnapshotOfView:_view
Expand Down
Loading

0 comments on commit 88e0bbc

Please sign in to comment.