Skip to content

Commit

Permalink
Add convert compatible of NSString for bridge message data (#24630)
Browse files Browse the repository at this point in the history
Summary:
Fixes https://twitter.com/estevao_lucas/status/1117572702083190785?s=215 in #24626 . Now we try to convert any id to `NSString`, not throw error.

cc. cpojer .

[iOS] [Fixed] - Add convert compatible of NSString for bridge message data
Pull Request resolved: #24630

Differential Revision: D15120205

Pulled By: cpojer

fbshipit-source-id: 4849a8e941410b292f971608a9cdb38c11502445
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Apr 29, 2019
1 parent 382f088 commit ffa3b0d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion React/Base/RCTConvert.m
Expand Up @@ -53,12 +53,21 @@ + (type *)type:(id)json { return json; }

RCT_JSON_CONVERTER(NSArray)
RCT_JSON_CONVERTER(NSDictionary)
RCT_JSON_CONVERTER(NSString)
RCT_JSON_CONVERTER(NSNumber)

RCT_CUSTOM_CONVERTER(NSSet *, NSSet, [NSSet setWithArray:json])
RCT_CUSTOM_CONVERTER(NSData *, NSData, [json dataUsingEncoding:NSUTF8StringEncoding])

+ (NSString *)NSString:(id)json
{
if ([json isKindOfClass:NSString.class]) {
return json;
} else if (json && json != (id)kCFNull) {
return [NSString stringWithFormat:@"%@",json];
}
return nil;
}

+ (NSIndexSet *)NSIndexSet:(id)json
{
json = [self NSNumberArray:json];
Expand Down

0 comments on commit ffa3b0d

Please sign in to comment.