iOS Development-ui Learn the difference between-nsbundle and nshomedirectory

Source: Internet
Author: User

The difference between NSBundle and Nsurl:

In the project to add a file, this routine added is Aa.txt, the content of the file is Baidu: www.baidu.com, now to use NSBundle and Nsurl respectively to get the content, the code is as follows:

1 //Read File contents2 //Method 1: Read by file path3NSString *pathbundle = [[NSBundle mainbundle]pathforresource:@"AA"OfType:@"txt"];4NSString *outstringbundle =[NSString stringwithcontentsoffile:pathbundle encoding:nsutf8stringencoding Error:nil];5     6 //Method 2: Read by URL7Nsurl *pathurl = [[NSBundle mainbundle]urlforresource:@"AA"Withextension:@"txt"Subdirectory:nil];8NSString *outstringurl =[NSString stringwithcontentsofurl:pathurl encoding:nsutf8stringencoding Error:nil];9     TenNSLog (@"%@\n////////\n%@", Outstringbundle,outstringurl);

The output results are as follows:

1 $---£ º02.939 sandbox mechanism and file path [11786:  518929] Baidu: www.baidu.com2////////3 Baidu: www.baidu.com

iOS Development-ui Learn the difference between-nsbundle and nshomedirectory

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.