For example,a NSInteger
8 ,is in the NSRange
(4,10).
I have checked NSRange
API and didn't find one method to determine it.
Asked
Active
Viewed 486 times
0

Henson Fang
- 1,177
- 7
- 30
-
see this http://stackoverflow.com/questions/4139085/how-can-i-use-nsrange-with-integers-to-simplify-my-code – Anbu.Karthik Mar 29 '17 at 05:58
-
Also see http://stackoverflow.com/a/5223205/1226963 – rmaddy Mar 29 '17 at 06:09
-
Possible duplicate of [How to test to see if number is in range using Objective-C?](http://stackoverflow.com/questions/5223039/how-to-test-to-see-if-number-is-in-range-using-objective-c) – Ronak Chaniyara Mar 29 '17 at 06:33
1 Answers
0
Use NSLocationInRange
:
NSInteger num = 8;
NSRange range = NSMakeRange(4, 10); // 4 - 14
if (NSLocationInRange(num, range)) {
// num in range
}

rmaddy
- 314,917
- 42
- 532
- 579