Last active
March 1, 2016 16:39
-
-
Save jaderfeijo/b309dd243e6eeca20552 to your computer and use it in GitHub Desktop.
NSArray+Random
This file contains hidden or 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
| // | |
| // Created by Jader Feijo on 03/12/2014. | |
| // Copyright (c) 2014 Movinpixel. All rights reserved. | |
| // | |
| // @license MIT | |
| #import <Foundation/Foundation.h> | |
| @interface NSArray (Random) | |
| - (id)randomObject; | |
| @end |
This file contains hidden or 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
| // | |
| // NSArray+Random.m | |
| // iFreeXDaily | |
| // | |
| // Created by Jader Feijo on 03/12/2014. | |
| // Copyright (c) 2014 Movinpixel. All rights reserved. | |
| // | |
| // @license MIT | |
| #import "NSArray+Random.h" | |
| #import "NSNumber+Random.h" | |
| @implementation NSArray (Random) | |
| - (id)randomObject { | |
| if ([self count] > 0) { | |
| return [self objectAtIndex:[NSNumber randomIntegerBetween:0 and:([self count] - 1)]]; | |
| } else { | |
| return nil; | |
| } | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment