Cog/Utils/NSDictionary+Optional.m
Christopher Snowhill 234fb63267 Housecleaning: Cleaned up a bunch of warnings
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>
2025-06-24 03:54:05 -07:00

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