What should I do if NSBundle pathForResource cannot get the value?

Source: Internet
Author: User

The Code is as follows:

 
 
  1. NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"]; 
  2.       NSLog(@"path = %@", path); 
  3.       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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.