When I run the code below I get
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]
I understand that at some point in the loop not existed index of the array is reached.
How to deal with that ?
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSArray *t = [NSTimeZone knownTimeZoneNames];
for(id x in t)
{
NSArray *tmpArray = [x componentsSeparatedByString:@"/"];
NSLog(@"%@", [tmpArray objectAtIndex:1]);
}
[pool drain];
return 0;
}
Not all time zones names contain a slash. For example, the
UTCtime zone name does not contain a slash. SotmpArraymight only contain one string, at index 0.Perhaps this will do what you want: