Source

DTFoundation / DTFoundation / NSArray+DTExtras.m

Full commit
//
//  NSArray+DTExtras.m
//  DTKit
//
//  Created by Daniel Tull on 30.09.2009.
//  Copyright 2009 Daniel Tull. All rights reserved.
//

#import "NSArray+DTExtras.h"


@implementation NSArray (DTExtras)

- (BOOL)isEmpty {
	return ([self count] == 0);
}

- (id)firstObject {
	if ([self isEmpty])
		return nil;
	
	return [self objectAtIndex:0];
}

- (NSArray *)subarrayWithObjectsOfClass:(Class)aClass {
	
	NSMutableArray *mArray = [[NSMutableArray alloc] init];
	
	for (id o in self)
		if ([o isKindOfClass:aClass])
			[mArray addObject:o];
	
	NSArray *subarray = [NSArray arrayWithArray:mArray];
	[mArray release];
	return subarray;
}

- (BOOL)containsObjectOfClass:(Class)aClass {
	
	for (id o in self)
		if ([o isKindOfClass:aClass])
			return YES;
	
	return NO;
}

@end