Skip to content

Commit

Permalink
Added files
Browse files Browse the repository at this point in the history
  • Loading branch information
Dick Verbunt authored and Dick Verbunt committed Jun 11, 2012
1 parent 5342d25 commit f090fe7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions NSArray+DVExtention.h
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
48 changes: 48 additions & 0 deletions NSArray+DVExtention.m
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

0 comments on commit f090fe7

Please sign in to comment.