MSRandomIndexPath 0.1.6

MSRandomIndexPath 0.1.6

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.


Downloads

Total3
Week0
Month0

Installs

Apps1
powered by Segment

GitHub

Stars0
Watchers1
Forks0
Issues0
Contributors2
Pull Requests0

Code

Files2
LOCLines of Code 26


  • By
  • Murray Sagal
+ (NSIndexPath *)randomIndexPathInArrays:(NSArray *)arrays
                     excludingIndexPaths:(NSSet *)excludedIndexPaths;

Returns a random index path valid for one of the arrays in arrays. arrays can't be nil and must be an array of arrays. The returned index path will not be in the set of excludedIndexPaths. excludedIndexPaths can be nil or empty.

The order of the arrays in arrays is important. The first array is section 0, the second array is section 1, and so on. The size of the arrays can vary but an array cannot be empty.

Returns nil if:

  • arrays is nil
  • any of the arrays in arrays is empty
  • any of the objects in arrays is not an array
  • the number of items in excludedIndexPaths is greater than or equal to the total number of elements for all the arrays in arrays

This method will take longer to return as the number of items in excludedIndexPaths grows as a percent of the total number of elements for all the arrays in arrays.

Installation

MSRandomIndexPath uses arc4random_uniform which was available since iOS 4.3.

Source Files

Alternatively you can directly add the two NSIndexPath+RandomAdditions.* source files to your project.

Tests

The example Xcode project contains a suite of tests so you can use this method with confidence.

If you copy the test file to your project you may need to configure the project so the test target will recognize the files.

  1. Select your project in the Project Navigator pane.
  2. Select your project in the Projects and Targets pane.
  3. You must be on the Info tab.
  4. In Configurations expand Debug and your project.
  5. In Tests select Pods from the popup.