And a bunch of potential memory leaks, and some misbehavior that could occur due to not checking for errors properly. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
17 lines
549 B
Objective-C
17 lines
549 B
Objective-C
#import "NSDictionary+Merge.h"
|
|
|
|
@implementation NSDictionary (Optional)
|
|
|
|
+ (NSDictionary *_Nonnull)initWithOptionalObjects:(const id _Nullable [_Nullable])objects forKeys:(id<NSCopying> const _Nullable [_Nullable])keys count:(NSUInteger)cnt {
|
|
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
|
|
if(keys && objects && cnt) {
|
|
for(NSUInteger i = 0; i < cnt; ++i) {
|
|
if(keys[i] && objects[i]) {
|
|
[dictionary setObject:objects[i] forKey:keys[i]];
|
|
}
|
|
}
|
|
}
|
|
return [NSDictionary dictionaryWithDictionary:dictionary];
|
|
}
|
|
|
|
@end
|