diff --git a/NSArray+sample.m b/NSArray+sample.m index 9bc5487..bfd8071 100644 --- a/NSArray+sample.m +++ b/NSArray+sample.m @@ -3,8 +3,10 @@ @implementation NSArray (YOLO) -- (id)sample { - return self[arc4random_uniform((u_int32_t)self.count)]; +- (id)sample { + return self.count == 0 + ? nil + : self[arc4random_uniform((u_int32_t)self.count)]; } @end diff --git a/YOLOKit.podspec b/YOLOKit.podspec index 3ab8513..fa8a5d5 100644 --- a/YOLOKit.podspec +++ b/YOLOKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'YOLOKit' - s.version = '11' + s.version = '11.0.1' s.source = { :git => 'https://github.com/mxcl/YOLOKit.git', :tag => s.version } s.requires_arc = true s.summary = 'A delightful library for enumerating Foundation objects.' diff --git a/tests b/tests index 6539afa..2f60546 100755 --- a/tests +++ b/tests @@ -592,6 +592,10 @@ int main() { }); } +- (void)testEmptySample { + XCTAssertNil(@[].sample); +} + @end