Fixed nil safety issue in RKSounds

This commit is contained in:
Nick Lockwood 2015-06-23 05:17:36 -07:00
parent bd3f9763f7
commit 9ed2bd6285
2 changed files with 21 additions and 0 deletions

View File

@ -46,6 +46,9 @@
+ (NSURL *)NSURL:(id)json;
+ (NSURLRequest *)NSURLRequest:(id)json;
typedef NSURL RCTFileURL;
+ (RCTFileURL *)RCTFileURL:(id)json;
+ (NSDate *)NSDate:(id)json;
+ (NSTimeZone *)NSTimeZone:(id)json;
+ (NSTimeInterval)NSTimeInterval:(id)json;
@ -95,6 +98,9 @@ typedef NSArray NSDictionaryArray;
typedef NSArray NSURLArray;
+ (NSURLArray *)NSURLArray:(id)json;
typedef NSArray RCTFileURLArray;
+ (RCTFileURLArray *)RCTFileURLArray:(id)json;
typedef NSArray NSNumberArray;
+ (NSNumberArray *)NSNumberArray:(id)json;

View File

@ -122,6 +122,20 @@ RCT_CONVERTER(NSString *, NSString, description)
return URL ? [NSURLRequest requestWithURL:URL] : nil;
}
+ (RCTFileURL *)RCTFileURL:(id)json
{
NSURL *fileURL = [self NSURL:json];
if (![fileURL isFileURL]) {
RCTLogError(@"URI must be a local file, '%@' isn't.", fileURL);
return nil;
}
if (![[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]) {
RCTLogError(@"File '%@' could not be found.", fileURL);
return nil;
}
return fileURL;
}
+ (NSDate *)NSDate:(id)json
{
if ([json isKindOfClass:[NSNumber class]]) {
@ -854,6 +868,7 @@ NSArray *RCTConvertArrayValue(SEL type, id json)
RCT_ARRAY_CONVERTER(NSString)
RCT_ARRAY_CONVERTER(NSDictionary)
RCT_ARRAY_CONVERTER(NSURL)
RCT_ARRAY_CONVERTER(RCTFileURL)
RCT_ARRAY_CONVERTER(NSNumber)
RCT_ARRAY_CONVERTER(UIColor)