I was making a basic method that takes a Flickr image URL and returns the image’s ID.
I’m passing the method the NSString @"http://farm6.staticflickr.com/5183/5629026092_c6762a118f".
The goal is to return the int: 5629026092, which is in the image’s URL and is the image’s ID.
Here is my method:
-(int)getImageIDFromFlickrURL:(NSString *)imageURL{
NSArray *objectsInURLArray = [imageURL componentsSeparatedByString:@"/"];
NSString *lastObjectInFlickrArray = [objectsInURLArray lastObject];
NSArray *dirtyFlickrIdArray = [lastObjectInFlickrArray componentsSeparatedByString:@"_"];
NSString *flickIDString = [dirtyFlickrIdArray objectAtIndex:0];
NSLog(@"flickr id string: %@",flickIDString);
int flickrID = [flickIDString intValue];
NSLog(@"id: %i",flickrID);
return flickrID;
}
The output in the console is:
2012-05-26 13:30:25.771 TestApp[1744:f803] flickr id string: 5629026092
2012-05-26 13:30:25.773 TestApp[1744:f803] id: 2147483647
Why is calling intValue deforming the actual number?
Use
long longinstead, your number is greater thanintcan handle (max being2147483647as you can see in your second log)