I am slightly confused as I am using this piece of code;
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Volumes/" error:nil];
int arraysize = sizeof dirContents;
to get an array of the contents of the "Volumes" direcoty, however when I output the array size it says that the array has 8 entries when there are only 4 files in that directory? This wouldn't be a problem but since I am using a for loop as soon as I get to;
NSString *volume1 = [dirContents objectAtIndex:4];
(4 being the value in the for loop) the application crashes and refuses to launch?
Thanks for any help
You should use int arraysize = [dirContents count]
to get the correct size.
sizeof
is a c-style operator that will not work correctly on Objective-C objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With