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
This commit is contained in:
rh389 2017-01-27 13:33:59 -08:00 committed by Facebook Github Bot
parent abf75fa23c
commit 9d6d8a24eb
2 changed files with 16 additions and 7 deletions

View File

@ -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) \ #define RCT_ARRAY_CONVERTER_NAMED(type, name) \
+ (NSArray<type *> *)type##Array:(id)json \ + (NSArray<type *> *)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)

View File

@ -558,14 +558,15 @@ RCT_ARRAY_CONVERTER(UIColor)
* representable json array values that require no conversion. * representable json array values that require no conversion.
*/ */
#if RCT_DEBUG #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 #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 #endif
#define RCT_JSON_ARRAY_CONVERTER(type) RCT_JSON_ARRAY_CONVERTER_NAMED(type, type)
RCT_JSON_ARRAY_CONVERTER(NSArray) RCT_JSON_ARRAY_CONVERTER(NSArray)
RCT_JSON_ARRAY_CONVERTER(NSString) RCT_JSON_ARRAY_CONVERTER(NSString)
RCT_JSON_ARRAY_CONVERTER(NSStringArray) RCT_JSON_ARRAY_CONVERTER_NAMED(NSArray<NSString *>, NSStringArray)
RCT_JSON_ARRAY_CONVERTER(NSDictionary) RCT_JSON_ARRAY_CONVERTER(NSDictionary)
RCT_JSON_ARRAY_CONVERTER(NSNumber) RCT_JSON_ARRAY_CONVERTER(NSNumber)