-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dick Verbunt
authored and
Dick Verbunt
committed
Jun 11, 2012
1 parent
5342d25
commit f090fe7
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// NSArray+NSArray_extention.h | ||
// | ||
// Created by Dick Verbunt on 6/2/12. | ||
// Copyright (c) 2012 Dickverbunt. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSArray (DVExtention) | ||
|
||
- (id)firstObject; //Get fisrst object | ||
- (NSArray *)shuffle; //Shuffles all objects in array | ||
- (NSArray *)objectsNotInArray:(NSArray *)array; //returns items that are not in the array | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |