Does anyone have any idea why the following causes the program to crash?
NSFileManager *filemgr;
NSString *currentpath = [filemgr currentDirectoryPath];
NSArray *filelist;
filemgr = [NSFileManager defaultManager];
filelist = [filemgr contentsOfDirectoryAtPath:currentpath error:nil];
int count=[filelist count];
for (int i = 0; i < count ; i++)
NSLog (@"%@", [filelist objectAtIndex: 1]);
As an added note, I am redirecting NSLog().
I think your crash message comes from your 2nd line where it you’re asking for the current directory. However, you allocated the variable on the 4th line, which is probably why it crashed. Instead, you should rearrange your code to something like this.
From what I see you’re doing, you’re declaring all of your variables first, which is why the error occurred. In Objective-C, it doesn’t matter where you declare your variables, but you must allocate and initialize it before you can use them.