Permalink
Browse files

Safe returning nil on randomObject when is empty

Implemented the same way it's implemented on firstObject.
  • Loading branch information...
marlonandrade committed Apr 18, 2013
1 parent 47e6ff7 commit 23423e2e17349d07905067f54b7603bb32ac3720
Showing with 4 additions and 0 deletions.
  1. +4 −0 SSToolkit/NSArray+SSToolkitAdditions.m
@@ -26,6 +26,10 @@ - (id)firstObject {
- (id)randomObject {
+ if ([self count] == 0) {
+ return nil;
+ }
+
return [self objectAtIndex:arc4random_uniform([self count])];
}

0 comments on commit 23423e2

Please sign in to comment.