Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

40 lines (28 sloc) 0.769 kb
//
// NSArray+SSToolkitAdditions.m
// SSToolkit
//
// Created by Sam Soffes on 8/19/09.
// Copyright 2009-2011 Sam Soffes. All rights reserved.
//
#import "NSArray+SSToolkitAdditions.h"
@implementation NSArray (SSToolkitAdditions)
- (id)firstObject {
return [self objectAtIndex:0];
}
- (id)randomObject {
return [self objectAtIndex:arc4random() % [self count]];
}
- (NSArray *)shuffledArray {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self count]];
NSMutableArray *copy = [self mutableCopy];
while ([copy count] > 0) {
NSUInteger index = arc4random() % [copy count];
id objectToMove = [copy objectAtIndex:index];
[array addObject:objectToMove];
[copy removeObjectAtIndex:index];
}
[copy release];
return array;
}
@end
Jump to Line
Something went wrong with that request. Please try again.