PDA

View Full Version : Accessing Xcode Folder in NSMutableArray?




Blakeasd
May 1, 2011, 07:21 PM
I added a folder to Xcode with a collection of images, 456 images to be precise. I need to add these images to an NSMutableArray so I can later view them in an IKImageBrowserView. I could add each of these images manually to the NSMutableArray, but that would take a very long time. How can I access folders that are used by my program and add them to an NSMutableArray?
Thanks



Cromulent
May 1, 2011, 07:31 PM
I added a folder to Xcode with a collection of images, 456 images to be precise. I need to add these images to an NSMutableArray so I can later view them in an IKImageBrowserView. I could add each of these images manually to the NSMutableArray, but that would take a very long time. How can I access folders that are used by my program and add them to an NSMutableArray?
Thanks

Why would it take a long time? This is what loops are for.

larkost
May 1, 2011, 07:34 PM
You are vague with "added a folder to Xcode", so I will ask, did you add it to the project? Have you checked to see if these images are being copied into your application bundle? If so, then they are probably in Contents/Resources, and if they are distinct from everything else in /Resources, then you can enumerate that (filtering for only these images), and work from there.

chown33
May 1, 2011, 07:45 PM
NSFileManager. The Discovering Directory Contents methods.

Sydde
May 1, 2011, 11:10 PM
You should use [[NSBundle mainBundle] resourcePath] to locate your application's resource directory. Then you can use a NSFileManager method to either create an array of filenames from your subdirectory (by appending the folder name to the resource path as a path component) or create a directory enumerator. If you image folder has subfolders itself, you would use the directory enumerator to go through them easily, filtering out the folder names as you go.

As far as it being "manual", you only have to do it once.

Blakeasd
May 2, 2011, 03:19 PM
Thanks @Sydde it worked!