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

iOS Build a Vending Machine App in Swift Loading Data From a Resource Inventory Errors

Johnny Nguyen
Johnny Nguyen
3,875 Points

I don't understand much

I don't know why path is a String

let path = Bundle.main.path(forResource: name, ofType: type)

and what is he doing here?

let dictionary = NSDictionary(contentsOfFile: path)

1 Answer

missgeekbunny
missgeekbunny
37,033 Points

He's using a standard library function which takes the file name as a string and the type as a string because it takes those strings to pass as a string to the native operating system to fetch the file you specify in the function. He then is passing the path (which in this case is the plist file that he just grabbed) and passing it into another standard library function that transforms the information in the plist into data that you can actually use in the app. Functions like this are common when you have to get information from a file instead of something directly from the code itself.