Skip to content

Instantly share code, notes, and snippets.

@dot
Created July 15, 2011 11:32
Show Gist options
  • Save dot/1084528 to your computer and use it in GitHub Desktop.
Save dot/1084528 to your computer and use it in GitHub Desktop.
check int strict
#import <Foundation/Foundation.h>
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
// gcc intcheck.m -framework Foundation && ./a.out
int main(void) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSArray* test = [NSArray arrayWithObjects:@"123aa", @"123.0", @"123", @"-123", nil]; // f, f, t, t
for (NSString* i in test) {
if ([i isEqualToString: [NSString stringWithFormat:@"%d", [i intValue]]]) {
NSLog(@"%@ is integer!!", i);
} else {
NSLog(@"%@ is not integer!!", i);
}
}
[pool release];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment