For some methods I want them to return a range of values (from: 235, to: 245). I did this using NSRange
as a return value
- (NSRange)giveMeARangeForMyParameter:(NSString *)myParameter;
This works fine as long as the return value is an integer
range (e.g. location: 235, length: 10).
But now I have the problem that I need to return a float
range (e.g. location: 500.5, length: 0.4). I read in the doc that NSRange
is a typedefed struct with NSUIntegers
. Is it possible to typedef another struct for float
ranges? And if so, can there be a similar method to NSMakeRange(NSUInteger loc, NSUInteger len)
to create those float
ranges?
Although you could reuse one of several "pair objects" from the graphics library (you can pick from a
CGPoint
orCGSize
, or theirNS...
equivalents) thestruct
s behind these objects are so simple that it would be better to create your own:With the introduction of the IOS 9 SDK, a new structure has been added by Apple which best match the OP subject:
There are couple of useful helper functions to compare ranges too:
Yes, you can even go and look at the definitions of
NSRange
andNSMakeRange
(inNSRange.h
, easiest way to get there is to 'command click' onNSRange
name in Xcode) to see how to do it:If you just want an existing struct with 2 floats and you don't mind including GLKit, you could use GLKVector2. It also has a Make function.