aryaxt
aryaxt

Reputation: 77596

Cocoa - Read content of a file?

I'm just trying to read the content of a text file that is in my project in the main folder.

// file name is "logs"
// it returns nil
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"logs" ofType:nil];


// file name is "logs.txt"
// it returns nil
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"logs" ofType:@"txt"];

Questions:

Upvotes: 3

Views: 2405

Answers (1)

user557219
user557219

Reputation:

The fact that a file is present in your project directory doesn’t mean the file will be copied to the corresponding target application bundle. You need to add the file to the target via the Copy Bundle Resources build phase.

In order to inspect and edit the list of files that are copied to the bundle directory in Xcode 4:

  • Click your root project in Project Navigator
  • Click your target
  • Select Build Phases > Copy Bundle Resources

Note: when you add a file to the project via Xcode, the add file dialog gives you a choice of adding that file to a target so that you don’t need to do these steps later.

Upvotes: 6

Related Questions