How to access local files within project How to access local files within project xcode xcode

How to access local files within project


You need to ensure that you're accessing the file in the right place. Xcode places your resource files in the application's "application bundle" in the Resources directory. There are many ways to dig 'em out.

A common way is to get the pathname of a file in your bundle:

NSBundle *mainBundle = [NSBundle mainBundle];NSString *myFile = [mainBundle pathForResource: @"data" ofType: @"bin"];

If you have other files in nonstandard places in your bundle, there are variations to pathForResource that let your specify a directory name.

If you want to see the actual location on your hard-drive that the simulator is using so you can inspect it, you can say:

NSLog(@"Main bundle path: %@", mainBundle);NSLog(@"myFile path: %@", myFile);

Search for the "Bundle Programming Guide" in the Xcode documentation library to get started. :-)


Use NSBundle class for that. For Example:

NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"bin"];NSInputStream *is = [[NSInputStream alloc] initWithFileAtPath:path];...


Indeed calling [is open] is needed even though you "initialiseWithFileAtPath". I would think the initialisation would automatically open the file for you, but it doesn't.