Created
July 21, 2012 16:34
-
-
Save pcperini/3156347 to your computer and use it in GitHub Desktop.
Quick Ranges from NSNumbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .h | |
@interface NSNumber (Ranges) | |
- (NSRange)to:(NSNumber *)rangeEnd; | |
- (BOOL)isInRange:(NSRange)range; | |
@end | |
// .m | |
@implementation NSNumber (Ranges) | |
- (NSRange)to:(NSNumber *)rangeEnd | |
{ | |
return NSMakeRange([self intValue], [rangeEnd intValue] - [self intValue]); | |
} | |
- (BOOL)isInRange:(NSRange)range | |
{ | |
return ([self intValue] >= range.location) && ([self intValue] <= (range.length + range.location)); | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .h | |
@interface NSNumber (Ranges) | |
- (NSRange)to:(NSNumber *)rangeEnd; | |
- (BOOL)isInRange:(NSRange)range; | |
@end | |
// .m | |
@implementation NSNumber (Ranges) | |
- (NSRange)to:(NSNumber *)rangeEnd | |
{ | |
return NSMakeRange([self intValue], [rangeEnd intValue] - [self intValue]); | |
} | |
- (BOOL)isInRange:(NSRange)range | |
{ | |
return ([self intValue] >= range.location) && ([self intValue] <= (range.length + range.location)); | |
} | |
@end | |
// use | |
NSLog(@"%@", [@"pcperini" substringWithRange: [@2 to: @7]]); | |
// logs 'perini` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment