-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSArray+DVExtention.m
More file actions
48 lines (38 loc) · 874 Bytes
/
NSArray+DVExtention.m
File metadata and controls
48 lines (38 loc) · 874 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
44
45
46
47
48
//
// NSArray+NSArray_extention.m
//
// Created by Dick Verbunt on 6/2/12.
// Copyright (c) 2012 Dickverbunt. All rights reserved.
//
#import "NSArray+DVExtention.h"
@implementation NSArray (DVExtention)
- (id)firstObject
{
if (self.count > 0) {
return [self objectAtIndex:0];
}
return nil;
}
- (NSArray *)objectsNotInArray:(NSArray *)array
{
NSMutableArray *tmpArray = [NSMutableArray array];
for (id object in self)
{
if(![array containsObject:object])
{
[tmpArray addObject:object];
}
}
return [NSArray arrayWithArray:tmpArray];
}
- (NSArray *)shuffle
{
NSMutableArray *tmpArray = [NSMutableArray arrayWithCapacity:[self count]];
for (id object in self)
{
NSUInteger randomPosition = arc4random() % (tmpArray.count + 1);
[tmpArray insertObject:object atIndex:randomPosition];
}
return [NSArray arrayWithArray:tmpArray];
}
@end