diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTContextExecutorTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTContextExecutorTests.m index 1ba3eaf56..ba2bf87bb 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTContextExecutorTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTContextExecutorTests.m @@ -57,7 +57,7 @@ static uint64_t _get_time_nanoseconds(void) JSContextGroupRef group = JSContextGroupCreate(); JSGlobalContextRef context = JSGlobalContextCreateInGroup(group, NULL); - id message = @[@[@1, @2, @3, @4], @[@{@"a": @1}, @{@"b": @2}], [NSNull null]]; + id message = @[@[@1, @2, @3, @4], @[@{@"a": @1}, @{@"b": @2}], (id)kCFNull]; NSString *code = RCTJSONStringify(message, NULL); JSStringRef script = JSStringCreateWithCFString((__bridge CFStringRef)code); JSValueRef error = NULL; diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_NSURLTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_NSURLTests.m index 05c07fa06..c36c09a8e 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_NSURLTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_NSURLTests.m @@ -28,7 +28,7 @@ TEST_PATH(name, _input, [[[NSBundle mainBundle] bundlePath] stringByAppendingPat // Basic tests TEST_URL(basic, @"http://example.com", @"http://example.com") -TEST_URL(null, [NSNull null], nil) +TEST_URL(null, (id)kCFNull, nil) // Local files TEST_PATH(fileURL, @"file:///blah/hello.jsbundle", @"/blah/hello.jsbundle") diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index 75798efaf..4883aa647 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -10,6 +10,7 @@ #import "RCTActionSheetManager.h" #import "RCTLog.h" +#import "RCTUtils.h" @interface RCTActionSheetManager () @@ -90,7 +91,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options if (activityError) { failureCallback(@[[activityError localizedDescription]]); } else { - successCallback(@[@(completed), (activityType ?: [NSNull null])]); + successCallback(@[@(completed), RCTNullIfNil(activityType)]); } }; } else { @@ -100,7 +101,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options if (![UIActivityViewController instancesRespondToSelector:@selector(completionWithItemsHandler)]) { // Legacy iOS 7 implementation share.completionHandler = ^(NSString *activityType, BOOL completed) { - successCallback(@[@(completed), (activityType ?: [NSNull null])]); + successCallback(@[@(completed), RCTNullIfNil(activityType)]); }; } else @@ -109,7 +110,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options { // iOS 8 version share.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) { - successCallback(@[@(completed), (activityType ?: [NSNull null])]); + successCallback(@[@(completed), RCTNullIfNil(activityType)]); }; } } diff --git a/Libraries/LinkingIOS/RCTLinkingManager.m b/Libraries/LinkingIOS/RCTLinkingManager.m index eec17a012..8d4846a3b 100644 --- a/Libraries/LinkingIOS/RCTLinkingManager.m +++ b/Libraries/LinkingIOS/RCTLinkingManager.m @@ -11,6 +11,7 @@ #import "RCTBridge.h" #import "RCTEventDispatcher.h" +#import "RCTUtils.h" NSString *const RCTOpenURLNotification = @"RCTOpenURLNotification"; @@ -76,7 +77,7 @@ RCT_EXPORT_METHOD(canOpenURL:(NSURL *)URL - (NSDictionary *)constantsToExport { NSURL *initialURL = _bridge.launchOptions[UIApplicationLaunchOptionsURLKey]; - return @{@"initialURL": [initialURL absoluteString] ?: [NSNull null]}; + return @{@"initialURL": RCTNullIfNil([initialURL absoluteString])}; } @end diff --git a/Libraries/Network/RCTDataManager.m b/Libraries/Network/RCTDataManager.m index 05a51c169..56e13af70 100644 --- a/Libraries/Network/RCTDataManager.m +++ b/Libraries/Network/RCTDataManager.m @@ -436,7 +436,7 @@ RCT_EXPORT_MODULE() NSArray *responseJSON = @[ request.requestID, - error.localizedDescription ?: [NSNull null], + RCTNullIfNil(error.localizedDescription), ]; [_bridge.eventDispatcher sendDeviceEventWithName:@"didCompleteNetworkResponse" diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m index 12d6ba456..1c034a9b7 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m @@ -11,6 +11,7 @@ #import "RCTBridge.h" #import "RCTEventDispatcher.h" +#import "RCTUtils.h" #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0 @@ -172,7 +173,7 @@ RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback) - (NSDictionary *)constantsToExport { return @{ - @"initialNotification": _initialNotification ?: [NSNull null] + @"initialNotification": RCTNullIfNil(_initialNotification), }; } diff --git a/Libraries/WebSocket/RCTWebSocketManager.m b/Libraries/WebSocket/RCTWebSocketManager.m index 2622afcd6..e859fd965 100644 --- a/Libraries/WebSocket/RCTWebSocketManager.m +++ b/Libraries/WebSocket/RCTWebSocketManager.m @@ -13,6 +13,7 @@ #import "RCTEventDispatcher.h" #import "RCTSRWebSocket.h" #import "RCTSparseArray.h" +#import "RCTUtils.h" @implementation RCTSRWebSocket (React) @@ -107,7 +108,7 @@ RCT_EXPORT_METHOD(close:(NSNumber *)socketID) { [_bridge.eventDispatcher sendDeviceEventWithName:@"websocketClosed" body:@{ @"code": @(code), - @"reason": reason ? reason : [NSNull null], + @"reason": RCTNullIfNil(reason), @"clean": @(wasClean), @"id": webSocket.reactTag }]; diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 998fb7bca..5b63b1d0b 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -449,7 +449,7 @@ case _value: { \ // Set arguments NSUInteger index = 0; for (id json in arguments) { - id arg = (json == [NSNull null]) ? nil : json; + id arg = RCTNilIfNull(json); void (^block)(RCTBridge *, NSNumber *, NSInvocation *, NSUInteger, id) = _argumentBlocks[index]; block(bridge, context, invocation, index + 2, arg); index++; @@ -1012,7 +1012,7 @@ RCT_INNER_BRIDGE_ONLY(_invokeAndProcessModule:(NSString *)module method:(NSStrin if (queue) { _queuesByID[moduleID] = queue; } else { - _queuesByID[moduleID] = [NSNull null]; + _queuesByID[moduleID] = (id)kCFNull; } } @@ -1266,8 +1266,8 @@ RCT_INNER_BRIDGE_ONLY(_invokeAndProcessModule:(NSString *)module method:(NSStrin context:context callback:^(id json, NSError *error) { RCTProfileEndEvent(@"FetchApplicationScriptCallbacks", @"js_call,init", @{ - @"json": json ?: [NSNull null], - @"error": error ?: [NSNull null], + @"json": RCTNullIfNil(json), + @"error": RCTNullIfNil(error), }); [self _handleBuffer:json context:context]; @@ -1293,7 +1293,7 @@ RCT_INNER_BRIDGE_ONLY(_invokeAndProcessModule:(NSString *)module method:(NSStrin queue = _queuesByID[moduleID]; } - if (queue == [NSNull null]) { + if (queue == (id)kCFNull) { [_javaScriptExecutor executeBlockOnJavaScriptQueue:block]; } else { dispatch_async(queue ?: _methodQueue, block); @@ -1509,7 +1509,7 @@ RCT_INNER_BRIDGE_ONLY(_invokeAndProcessModule:(NSString *)module method:(NSStrin @"module": method.moduleClassName, @"method": method.JSMethodName, @"selector": NSStringFromSelector(method.selector), - @"args": RCTJSONStringify(params ?: [NSNull null], NULL), + @"args": RCTJSONStringify(RCTNullIfNil(params), NULL), }); return YES; diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 0a08326c7..e244d988b 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -54,7 +54,7 @@ RCT_CONVERTER(NSString *, NSString, description) RCTLogConvertError(json, "a number"); } return number; - } else if (json && json != [NSNull null]) { + } else if (json && json != (id)kCFNull) { RCTLogConvertError(json, "a number"); } return nil; @@ -141,7 +141,7 @@ RCT_CONVERTER(NSString *, NSString, description) "Expected format: YYYY-MM-DD'T'HH:mm:ss.sssZ", json); } return date; - } else if (json && json != [NSNull null]) { + } else if (json && json != (id)kCFNull) { RCTLogConvertError(json, "a date"); } return nil; diff --git a/React/Base/RCTTouchHandler.m b/React/Base/RCTTouchHandler.m index 0a2ca61a7..5c66aa49e 100644 --- a/React/Base/RCTTouchHandler.m +++ b/React/Base/RCTTouchHandler.m @@ -107,8 +107,8 @@ typedef NS_ENUM(NSInteger, RCTTouchEventType) { NSMutableDictionary *reactTouch = [[NSMutableDictionary alloc] initWithCapacity:9]; reactTouch[@"target"] = reactTag; reactTouch[@"identifier"] = @(touchID); - reactTouch[@"touches"] = [NSNull null]; // We hijack this touchObj to serve both as an event - reactTouch[@"changedTouches"] = [NSNull null]; // and as a Touch object, so making this JIT friendly. + reactTouch[@"touches"] = (id)kCFNull; // We hijack this touchObj to serve both as an event + reactTouch[@"changedTouches"] = (id)kCFNull; // and as a Touch object, so making this JIT friendly. // Add to arrays [_touchViews addObject:targetView]; diff --git a/React/Executors/RCTContextExecutor.m b/React/Executors/RCTContextExecutor.m index 07fd562c4..2bd6b7ae5 100644 --- a/React/Executors/RCTContextExecutor.m +++ b/React/Executors/RCTContextExecutor.m @@ -137,7 +137,7 @@ static JSValueRef RCTConsoleProfile(JSContextRef context, JSObjectRef object, JS profileName = [NSString stringWithFormat:@"Profile %d", profileCounter++]; } - id profileInfo = [NSNull null]; + id profileInfo = (id)kCFNull; if (argumentCount > 1 && !JSValueIsUndefined(context, arguments[1])) { profileInfo = @[RCTJSValueToNSString(context, arguments[1])]; } diff --git a/React/Modules/RCTAsyncLocalStorage.m b/React/Modules/RCTAsyncLocalStorage.m index 76f7fa885..a7f389282 100644 --- a/React/Modules/RCTAsyncLocalStorage.m +++ b/React/Modules/RCTAsyncLocalStorage.m @@ -164,14 +164,14 @@ RCT_EXPORT_MODULE() return errorOut; } id value = [self _getValueForKey:key errorOut:&errorOut]; - [result addObject:@[key, value ?: [NSNull null]]]; // Insert null if missing or failure. + [result addObject:@[key, RCTNullIfNil(value)]]; // Insert null if missing or failure. return errorOut; } - (NSString *)_getValueForKey:(NSString *)key errorOut:(NSDictionary **)errorOut { id value = _manifest[key]; // nil means missing, null means there is a data file, anything else is an inline value. - if (value == [NSNull null]) { + if (value == (id)kCFNull) { NSString *filePath = [self _filePathForKey:key]; value = RCTReadFile(filePath, key, errorOut); } @@ -195,7 +195,7 @@ RCT_EXPORT_MODULE() NSString *filePath = [self _filePathForKey:key]; NSError *error; if (value.length <= kInlineValueThreshold) { - if (_manifest[key] && _manifest[key] != [NSNull null]) { + if (_manifest[key] && _manifest[key] != (id)kCFNull) { // If the value already existed but wasn't inlined, remove the old file. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; } @@ -206,7 +206,7 @@ RCT_EXPORT_MODULE() if (error) { errorOut = RCTMakeError(@"Failed to write value.", error, @{@"key": key}); } else { - _manifest[key] = [NSNull null]; // Mark existence of file with null, any other value is inline data. + _manifest[key] = (id)kCFNull; // Mark existence of file with null, any other value is inline data. } return errorOut; } @@ -223,7 +223,7 @@ RCT_EXPORT_METHOD(multiGet:(NSArray *)keys id errorOut = [self _ensureSetup]; if (errorOut) { - callback(@[@[errorOut], [NSNull null]]); + callback(@[@[errorOut], (id)kCFNull]); return; } NSMutableArray *errors; @@ -232,7 +232,7 @@ RCT_EXPORT_METHOD(multiGet:(NSArray *)keys id keyError = [self _appendItemForKey:key toArray:result]; RCTAppendError(keyError, &errors); } - callback(@[errors ?: [NSNull null], result]); + callback(@[RCTNullIfNil(errors), result]); } RCT_EXPORT_METHOD(multiSet:(NSArray *)kvPairs @@ -250,7 +250,7 @@ RCT_EXPORT_METHOD(multiSet:(NSArray *)kvPairs } [self _writeManifest:&errors]; if (callback) { - callback(@[errors ?: [NSNull null]]); + callback(@[RCTNullIfNil(errors)]); } } @@ -282,7 +282,7 @@ RCT_EXPORT_METHOD(multiMerge:(NSArray *)kvPairs } [self _writeManifest:&errors]; if (callback) { - callback(@[errors ?: [NSNull null]]); + callback(@[RCTNullIfNil(errors)]); } } @@ -306,7 +306,7 @@ RCT_EXPORT_METHOD(multiRemove:(NSArray *)keys } [self _writeManifest:&errors]; if (callback) { - callback(@[errors ?: [NSNull null]]); + callback(@[RCTNullIfNil(errors)]); } } @@ -323,7 +323,7 @@ RCT_EXPORT_METHOD(clear:(RCTResponseSenderBlock)callback) errorOut = [self _writeManifest:nil]; } if (callback) { - callback(@[errorOut ?: [NSNull null]]); + callback(@[RCTNullIfNil(errorOut)]); } } @@ -331,9 +331,9 @@ RCT_EXPORT_METHOD(getAllKeys:(RCTResponseSenderBlock)callback) { id errorOut = [self _ensureSetup]; if (errorOut) { - callback(@[errorOut, [NSNull null]]); + callback(@[errorOut, (id)kCFNull]); } else { - callback(@[[NSNull null], [_manifest allKeys]]); + callback(@[(id)kCFNull, [_manifest allKeys]]); } } diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 178281074..2de427ed0 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -471,7 +471,7 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa [frames addObject:[NSValue valueWithCGRect:shadowView.frame]]; [areNew addObject:@(shadowView.isNewView)]; [parentsAreNew addObject:@(shadowView.superview.isNewView)]; - id event = [NSNull null]; + id event = (id)kCFNull; if (shadowView.hasOnLayout) { event = @{ @"target": shadowView.reactTag, @@ -519,7 +519,7 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa void (^completion)(BOOL finished) = ^(BOOL finished) { completionsCalled++; - if (event != [NSNull null]) { + if (event != (id)kCFNull) { [self.bridge.eventDispatcher sendInputEventWithName:@"topLayout" body:event]; } if (callback && completionsCalled == frames.count - 1) { @@ -753,7 +753,7 @@ static BOOL RCTCallPropertySetter(NSString *key, SEL setter, id value, id view, // TODO: cache respondsToSelector tests if ([manager respondsToSelector:setter]) { - if (value == [NSNull null]) { + if (value == (id)kCFNull) { value = nil; } @@ -906,7 +906,7 @@ RCT_EXPORT_METHOD(blur:(NSNumber *)reactTag) RCT_EXPORT_METHOD(findSubviewIn:(NSNumber *)reactTag atPoint:(CGPoint)point callback:(RCTResponseSenderBlock)callback) { if (!reactTag) { - callback(@[[NSNull null]]); + callback(@[(id)kCFNull]); return; } @@ -920,7 +920,7 @@ RCT_EXPORT_METHOD(findSubviewIn:(NSNumber *)reactTag atPoint:(CGPoint)point call } callback(@[ - target.reactTag ?: [NSNull null], + RCTNullIfNil(target.reactTag), @(frame.origin.x), @(frame.origin.y), @(frame.size.width),