Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointspathforresource
abit of a silly question but how would you explain pathforresource to a someone with little knowledge to programming,please?
1 Answer
Amit Bijlani
Treehouse Guest TeacherThe files you add to your Xcode project are bundled into your application's binary. Just like you would install an app on your Mac OSX desktop, an iOS app gets installed on the device like an iPhone or iPad. Lets say you added images to your project to design your app, those images are made part of the application binary and installed locally on the device. Any files such as: images, plists, nibs, etc are all part of the application binary and are referred to as the main bundle. You can create your own bundle to group certain files but by default all the files are added to this main bundle. Your application is stored in specific folder which contains all these files. Just like Mac OSX, iOS or any OS has a filesystem which contains a directory structure that helps you navigate from one folder to the next.
The pathForResource method helps locate the folder where your app is installed and within that it locates the specific resource (read file). The pathForResource method returns a string which looks something like this "/private/var/applications/someuniqueidentifer/yourappname.app/imagename.png"
Now you know the exactly where that file is located and you can read it from disk and do something with it.