[NSArray arrayWithArray:] now requires a nonnull argument

Originator:steipete
Number:rdar://21290730 Date Originated:08-Jun-2015 03:32 PM
Status:Open Resolved:
Product:iOS Product Version:9.0b1
Classification:Security Reproducible:Always
 
Summary:
[NSArray arrayWithArray:] now requires a nonnull argument. This was traditionally used a lot in situations where you either have nil or an array, to make sure there’s always an array. Granted, I don’t see that explicitly documented, but it’s something I see a lot in code. (Same behaviour with NSDictionary and NSSet)

Should we continue to do that, or now always fall back to ?: and copy?

Consider code like this:

- (NSArray *)words {
    [self parseTextBlocksIfRequired];
    return [NSArray arrayWithArray:_words];
}

We used arrayWithArray: to 
a) make sure we return immutable data
b) make sure we always return an object and never nil.

I’ll recommend making the signature nullable to keep that useful behavior.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!