Merge branch 'develop' into feature/coding

This commit is contained in:
panxi 2020-01-09 16:18:35 -05:00
commit b3d293634f
2 changed files with 18 additions and 0 deletions

View File

@ -12,6 +12,9 @@
@interface NSArray (MFConvenience)
/// Creates an array with the given objects, ignoring any nil values, terminated by [NSNull null].
+ (nonnull NSArray *)safeArrayWithObjects:(nullable id)object, ...;
// Gets the object from the array and verfies that it is of a given type.
- (nullable id)objectAtIndex:(NSUInteger)index ofType:(nonnull Class)type;

View File

@ -10,6 +10,21 @@
@implementation NSArray (MFConvenience)
+ (NSArray *)safeArrayWithObjects:(id)object, ... {
NSMutableArray *array = [[NSMutableArray alloc] init];
va_list args;
va_start(args, object);
id nextObject = object;
while(nextObject != [NSNull null]) {
if (nextObject != nil) {
[array addObject:nextObject];
}
nextObject = va_arg(args, id);
}
va_end(args);
return array;
}
- (nullable id)objectAtIndex:(NSUInteger)index ofType:(nonnull Class)type {
id theObject = nil;