Add NSDictionary initWithOptionalObjects:forKeys:count: helper, to work around several places that may have been setting nil dictionary valies on placeholder dictionaries. Hopefully this fixes the crash someone logged recently. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
15 lines
482 B
Objective-C
15 lines
482 B
Objective-C
#import "NSDictionary+Merge.h"
|
|
|
|
@implementation NSDictionary (Optional)
|
|
|
|
+ (NSDictionary *)initWithOptionalObjects:(const id _Nonnull [_Nullable])objects forKeys:(id<NSCopying> const[])keys count:(NSUInteger)cnt {
|
|
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
|
|
for(NSUInteger i = 0; i < cnt; ++i) {
|
|
if(keys[i] && objects[i]) {
|
|
[dictionary setObject:objects[i] forKey:keys[i]];
|
|
}
|
|
}
|
|
return [NSDictionary dictionaryWithDictionary:dictionary];
|
|
}
|
|
|
|
@end
|