I'm trying to display my images in a tableView, I'm using NSFIleManager and NSDirectoryEnumerator to get all files in the current folder:
NSString *path = @"/Users/eagle/Documents/avatars";
NSFileManager *fileManager = NSFileManager.defaultManager;
NSDirectoryEnumerator *directoryEnum = [fileManager enumeratorAtPath:path];
NSString *file;
while (file = [directoryEnum nextObject])
{
// ...
}
the problem is that this line
file = [directoryEnum nextObject]
always returns nil, what gives?
I already made sure that this folder has no subfolders and contains only images, so what's the problem here?
The answer depends a little bit on what you're actually trying to achieve.
-
You can use
NSOpenPanel
to ask the user to "confirm" choice of a directory, thne save the result as a security-scoped bookmark to maintain access in future launches of your app. You can let the user choose or create the folder, or — by manipulating variousNSOpenPanel
settings — you can restrict the user to choosing only a specific folder. -
You can use a standard folder that's freely available to your sandboxed app's container. A likely choice, if you storing avatars, which may be sort-of persistent app-level data, is to put them in a sub-folder of the Application Support folder. The usual convention is to use your app's name or its bundle ID as the sub-folder name.