Ran Convert > To Modern Objective C Syntax

This commit is contained in:
Nick Lockwood
2015-08-24 09:14:33 -01:00
parent a57353b2b4
commit 88e0bbc469
80 changed files with 247 additions and 246 deletions

View File

@@ -61,7 +61,7 @@ RCT_EXPORT_MODULE()
selector:@selector(didReceiveNewContentSizeCategory:)
name:UIContentSizeCategoryDidChangeNotification
object:[UIApplication sharedApplication]];
self.contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
self.contentSizeCategory = [UIApplication sharedApplication].preferredContentSizeCategory;
}
return self;
}

View File

@@ -90,7 +90,7 @@ RCT_EXPORT_METHOD(alertWithArgs:(NSDictionary *)args
if (button.count != 1) {
RCTLogError(@"Button definitions should have exactly one key.");
}
NSString *buttonKey = [button.allKeys firstObject];
NSString *buttonKey = button.allKeys.firstObject;
NSString *buttonTitle = [button[buttonKey] description];
[alertView addButtonWithTitle:buttonTitle];
if ([buttonKey isEqualToString: @"cancel"]) {

View File

@@ -25,7 +25,7 @@ static NSString *RCTCurrentAppBackgroundState()
};
});
return states[@([[UIApplication sharedApplication] applicationState])] ?: @"unknown";
return states[@([UIApplication sharedApplication].applicationState)] ?: @"unknown";
}
@implementation RCTAppState

View File

@@ -66,7 +66,7 @@ static NSString *RCTGetStorageDirectory()
static NSString *storageDirectory = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
storageDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
storageDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
storageDirectory = [storageDirectory stringByAppendingPathComponent:RCTStorageDirectory];
});
return storageDirectory;
@@ -390,7 +390,7 @@ RCT_EXPORT_METHOD(getAllKeys:(RCTResponseSenderBlock)callback)
if (errorOut) {
callback(@[errorOut, (id)kCFNull]);
} else {
callback(@[(id)kCFNull, [_manifest allKeys]]);
callback(@[(id)kCFNull, _manifest.allKeys]);
}
}

View File

@@ -61,7 +61,7 @@ RCT_EXPORT_MODULE()
_showDate = [NSDate date];
if (!_window && !RCTRunningInTestEnvironment()) {
CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
_window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 22)];
_window.backgroundColor = [UIColor blackColor];
_window.windowLevel = UIWindowLevelStatusBar + 1;
@@ -76,10 +76,10 @@ RCT_EXPORT_MODULE()
}
NSString *source;
if ([URL isFileURL]) {
if (URL.fileURL) {
source = @"pre-bundled file";
} else {
source = [NSString stringWithFormat:@"%@:%@", [URL host], [URL port]];
source = [NSString stringWithFormat:@"%@:%@", URL.host, URL.port];
}
_label.text = [NSString stringWithFormat:@"Loading from %@...", source];

View File

@@ -64,7 +64,7 @@ static NSString *const RCTDevMenuSettingsKey = @"RCTDevMenu";
return self;
}
RCT_NOT_IMPLEMENTED(-init)
RCT_NOT_IMPLEMENTED(- (instancetype)init)
@end
@@ -210,7 +210,7 @@ RCT_EXPORT_MODULE()
} else {
RCTLogWarn(@"RCTSourceCode module scriptURL has not been set");
}
} else if (![sourceCodeModule.scriptURL isFileURL]) {
} else if (!(sourceCodeModule.scriptURL).fileURL) {
// Live reloading is disabled when running from bundled JS file
_liveReloadURL = [[NSURL alloc] initWithString:@"/onchange" relativeToURL:sourceCodeModule.scriptURL];
}
@@ -341,7 +341,7 @@ RCT_EXPORT_METHOD(show)
}
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = [actionSheet numberOfButtons] - 1;
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;
actionSheet.actionSheetStyle = UIBarStyleBlack;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view];

View File

@@ -32,7 +32,7 @@
UITableViewCell *_cachedMessageCell;
}
- (id)initWithFrame:(CGRect)frame
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
self.windowLevel = UIWindowLevelAlert + 1000;
@@ -89,7 +89,7 @@
return self;
}
RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
- (void)dealloc
{
@@ -99,7 +99,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
- (void)openStackFrameInEditor:(NSDictionary *)stackFrame
{
NSData *stackFrameJSON = [RCTJSONStringify(stackFrame, nil) dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[stackFrameJSON length]];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)stackFrameJSON.length];
NSMutableURLRequest *request = [NSMutableURLRequest new];
request.URL = [RCTConvert NSURL:@"http://localhost:8081/open-stack-frame"];
request.HTTPMethod = @"POST";
@@ -135,7 +135,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
{
self.hidden = YES;
[self resignFirstResponder];
[[[[UIApplication sharedApplication] delegate] window] makeKeyWindow];
[[UIApplication sharedApplication].delegate.window makeKeyWindow];
}
- (void)reload
@@ -152,17 +152,17 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
- (NSInteger)tableView:(__unused UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return section == 0 ? 1 : [_lastStackTrace count];
return section == 0 ? 1 : _lastStackTrace.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath section] == 0) {
if (indexPath.section == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"msg-cell"];
return [self reuseCell:cell forErrorMessage:_lastErrorMessage];
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
NSUInteger index = [indexPath row];
NSUInteger index = indexPath.row;
NSDictionary *stackFrame = _lastStackTrace[index];
return [self reuseCell:cell forStackFrame:stackFrame];
}
@@ -213,7 +213,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath section] == 0) {
if (indexPath.section == 0) {
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
@@ -228,8 +228,8 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath section] == 1) {
NSUInteger row = [indexPath row];
if (indexPath.section == 1) {
NSUInteger row = indexPath.row;
NSDictionary *stackFrame = _lastStackTrace[row];
[self openStackFrameInEditor:stackFrame];
}

View File

@@ -23,7 +23,7 @@ RCT_EXPORT_METHOD(getScriptText:(RCTResponseSenderBlock)successCallback
failureCallback:(RCTResponseErrorBlock)failureCallback)
{
if (self.scriptText && self.scriptURL) {
successCallback(@[@{@"text": self.scriptText, @"url":[self.scriptURL absoluteString]}]);
successCallback(@[@{@"text": self.scriptText, @"url": self.scriptURL.absoluteString}]);
} else {
failureCallback(RCTErrorWithMessage(@"Source code is not available"));
}
@@ -31,7 +31,7 @@ RCT_EXPORT_METHOD(getScriptText:(RCTResponseSenderBlock)successCallback
- (NSDictionary *)constantsToExport
{
NSString *URL = [self.bridge.bundleURL absoluteString] ?: @"";
NSString *URL = self.bridge.bundleURL.absoluteString ?: @"";
return @{@"scriptURL": URL};
}

View File

@@ -116,7 +116,7 @@ RCT_EXPORT_METHOD(setHidden:(BOOL)hidden
RCT_EXPORT_METHOD(setNetworkActivityIndicatorVisible:(BOOL)visible)
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:visible];
[UIApplication sharedApplication].networkActivityIndicatorVisible = visible;
}
@end

View File

@@ -145,7 +145,7 @@ RCT_EXPORT_MODULE()
}
// call timers that need to be called
if ([timersToCall count] > 0) {
if (timersToCall.count > 0) {
[_bridge enqueueJSCall:@"JSTimersExecution.callTimers" args:@[timersToCall]];
}

View File

@@ -731,7 +731,7 @@ RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag
}
}
NSArray *sortedIndices = [[destinationsToChildrenToAdd allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSArray *sortedIndices = [destinationsToChildrenToAdd.allKeys sortedArrayUsingSelector:@selector(compare:)];
for (NSNumber *reactIndex in sortedIndices) {
[container insertReactSubview:destinationsToChildrenToAdd[reactIndex] atIndex:reactIndex.integerValue];
}
@@ -760,7 +760,7 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag
[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){
id<RCTComponent> view = [componentData createViewWithTag:reactTag];
if ([view respondsToSelector:@selector(setBackgroundColor:)]) {
[(UIView *)view setBackgroundColor:backgroundColor];
((UIView *)view).backgroundColor = backgroundColor;
}
[componentData setProps:props forView:view];
if ([view respondsToSelector:@selector(reactBridgeDidFinishTransaction)]) {
@@ -810,7 +810,7 @@ RCT_EXPORT_METHOD(findSubviewIn:(nonnull NSNumber *)reactTag atPoint:(CGPoint)po
CGRect frame = [target convertRect:target.bounds toView:view];
while (target.reactTag == nil && target.superview != nil) {
target = [target superview];
target = target.superview;
}
callback(@[
@@ -858,7 +858,7 @@ RCT_EXPORT_METHOD(findSubviewIn:(nonnull NSNumber *)reactTag atPoint:(CGPoint)po
}
RCTProfileEndEvent(0, @"uimanager", @{
@"view_count": @([_viewRegistry count]),
@"view_count": @(_viewRegistry.count),
});
[self flushUIBlocks];
}
@@ -1005,7 +1005,7 @@ RCT_EXPORT_METHOD(measureViewsInRect:(CGRect)rect
return;
}
NSArray *childShadowViews = [shadowView reactSubviews];
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:[childShadowViews count]];
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:childShadowViews.count];
[childShadowViews enumerateObjectsUsingBlock:
^(RCTShadowView *childShadowView, NSUInteger idx, __unused BOOL *stop) {