Skip to content
This repository has been archived by the owner on Feb 16, 2019. It is now read-only.

Commit

Permalink
Safe returning nil on randomObject when is empty
Browse files Browse the repository at this point in the history
Implemented the same way it's implemented on firstObject.
  • Loading branch information
marlonandrade committed Apr 18, 2013
1 parent 47e6ff7 commit 23423e2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions SSToolkit/NSArray+SSToolkitAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ - (id)firstObject {


- (id)randomObject {
if ([self count] == 0) {
return nil;
}

return [self objectAtIndex:arc4random_uniform([self count])];
}

Expand Down

0 comments on commit 23423e2

Please sign in to comment.