From 9d6d8a24ebd0122827d14fc749cb187d222fbbd3 Mon Sep 17 00:00:00 2001 From: rh389 Date: Fri, 27 Jan 2017 13:33:59 -0800 Subject: [PATCH] RCTConvert: Deprecated NSStringArray typedef Summary: Eliminates a build warning related to the use of the deprecated `NSStringArray` typedef. This fix was more complex than I'd anticipated because `NSStringArray` was also being used as part of a macro-generated selector name, and in two different ways for debug/release. I've added a macro which allows the selector name to be specified explicitly, thus generally allowing for converters which return arrays of templated types. There's an argument for ditching `RCT_JSON_ARRAY_CONVERTER` in favour of `RCT_JSON_ARRAY_CONVERTER_NAMED` as they're both private, but `RCT_ARRAY_CONVERTER` is in the public API so we'd at least need to retain that. There are also arguments for ditching the use of the macro for the nested array case(s) - since afaik this is the only one at the moment. Feedback appreciated :) Tested with the `UIExplorer` unit tests and by diffing the preprocessor output of `RCTConvert.m` in both release and debug configs, verifying that they're identical apart from that `NSStringArray` is replaced by Closes https://github.com/facebook/react-native/pull/11799 Differential Revision: D4441197 fbshipit-source-id: 7535ebe6f8ad4566df742e805b0a64530d1b269f --- React/Base/RCTConvert.h | 16 ++++++++++++---- React/Base/RCTConvert.m | 7 ++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/React/Base/RCTConvert.h b/React/Base/RCTConvert.h index 520c216b5..18c2a157b 100644 --- a/React/Base/RCTConvert.h +++ b/React/Base/RCTConvert.h @@ -235,10 +235,18 @@ RCT_CUSTOM_CONVERTER(type, type, [RCT_DEBUG ? [self NSNumber:json] : json getter } /** - * This macro is used for creating converter functions for typed arrays. + * This macro is used for creating explicitly-named converter functions + * for typed arrays. */ -#define RCT_ARRAY_CONVERTER(type) \ -+ (NSArray *)type##Array:(id)json \ +#define RCT_ARRAY_CONVERTER_NAMED(type, name) \ ++ (NSArray *)name##Array:(id)json \ { \ - return RCTConvertArrayValue(@selector(type:), json); \ + return RCTConvertArrayValue(@selector(name:), json); \ } + +/** + * This macro is used for creating converter functions for typed arrays. + * RCT_ARRAY_CONVERTER_NAMED may be used when type contains characters + * which are disallowed in selector names. + */ +#define RCT_ARRAY_CONVERTER(type) RCT_ARRAY_CONVERTER_NAMED(type, type) diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 1a33d84b6..e26026440 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -558,14 +558,15 @@ RCT_ARRAY_CONVERTER(UIColor) * representable json array values that require no conversion. */ #if RCT_DEBUG -#define RCT_JSON_ARRAY_CONVERTER(type) RCT_ARRAY_CONVERTER(type) +#define RCT_JSON_ARRAY_CONVERTER_NAMED(type, name) RCT_ARRAY_CONVERTER_NAMED(type, name) #else -#define RCT_JSON_ARRAY_CONVERTER(type) + (NSArray *)type##Array:(id)json { return json; } +#define RCT_JSON_ARRAY_CONVERTER_NAMED(type, name) + (NSArray *)name##Array:(id)json { return json; } #endif +#define RCT_JSON_ARRAY_CONVERTER(type) RCT_JSON_ARRAY_CONVERTER_NAMED(type, type) RCT_JSON_ARRAY_CONVERTER(NSArray) RCT_JSON_ARRAY_CONVERTER(NSString) -RCT_JSON_ARRAY_CONVERTER(NSStringArray) +RCT_JSON_ARRAY_CONVERTER_NAMED(NSArray, NSStringArray) RCT_JSON_ARRAY_CONVERTER(NSDictionary) RCT_JSON_ARRAY_CONVERTER(NSNumber)