The Code is as follows:
- NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];
- NSLog(@"path = %@", path);
- NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
But the path is always null.
Master has been searching for a long time and finally found the answer.
Http://stackoverflow.com/questions/3949368/nsbundle-pathforresource-is-null
Record:
Command-line tool does not have bundle, so NSBundle is always null. If you want to use bundle to obtain resources, you need to add the target of the application.
According to the above modification, after adding a target, there is still a problem and the file still cannot be found
Then, Master performed the following operations:
After the file is added here and then run, the file can be obtained.
Then I tried to add the file in command-line tool according to the above method.
First, there is no bundle option by default.
Second, even if you manually add the build phrase, add the file and run it, you still cannot get the path.
So,To use bundle to obtain resources in a project, you must use application