Structure for representing a range with location and length in mulle-objc.
typedef struct _NSRange {
NSUInteger location; // Starting index
NSUInteger length; // Number of items
} NSRange;
NSMakeRange
- Create range structNSEmptyRange
- Create empty rangeNSEqualRanges
- Compare rangesNSLocationInRange
- Check if location in rangeNSMaxRange
- Get maximum locationNSUnionRange
- Combine rangesNSIntersectionRange
- Intersect ranges// Create range
NSRange range = NSMakeRange(0, 10);
// Check if location is in range
BOOL contains = NSLocationInRange(5, range); // YES
// Get maximum location
NSUInteger max = NSMaxRange(range); // 10
// Combine ranges
NSRange range1 = NSMakeRange(0, 5);
NSRange range2 = NSMakeRange(3, 5);
NSRange union = NSUnionRange(range1, range2); // {0, 8}
// Intersect ranges
NSRange intersection = NSIntersectionRange(range1, range2); // {3, 2}