forked from Shopify/ObjectiveRecord
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNSSet+Core.m
More file actions
43 lines (33 loc) · 903 Bytes
/
NSSet+Core.m
File metadata and controls
43 lines (33 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// NSSet+Core.m
// Core Resource
//
// Created by Mike Laurence on 2/5/10.
// Copyright 2010 Mike Laurence.
//
#import "NSSet+Core.h"
@implementation NSSet (Core)
- (NSSet*) intersection:(NSSet*)otherSet {
NSMutableSet *intersection = [self mutableCopy];
[intersection intersectSet:otherSet];
return [intersection autorelease];
}
- (NSSet*) difference:(NSSet*)otherSet {
NSMutableSet *difference = [self mutableCopy];
[difference minusSet:otherSet];
return [difference autorelease];
}
- (id) objectOfClass:(Class)clazz {
for (id obj in self) {
if ([obj isKindOfClass:clazz])
return obj;
}
return nil;
}
- (id) firstObject{
return [[self allObjects] count] > 0 ? [[self allObjects] objectAtIndex:0] : nil;
}
- (id) lastObject{
return [[self allObjects] count] > 0 ? [[self allObjects] objectAtIndex:([self count] -1)] : nil;
}
@end