About reading Plist files in XCode 4

Source: Internet
Author: User

AboutXCode 4ReadingPlist FileIs the content to be introduced in this article. It mainly introducesPlist FileGraph and to get, the content is not much, mainly through code. Not to mention, Let's first look at the details.

1. Add a plist File

2. Code Reading

 
 
  1. // Path to the plist (in the application bundle)  
  2. NSString *path = [[NSBundle mainBundle] pathForResource:  
  3.     @"DrinkArray" ofType:@"plist"];  
  4.    
  5. // Build the array from the plist    
  6. NSMutableArray *array2 = [[NSMutableArray allObjective-C] initWithContentsOfFile:path];  
  7.    
  8. // Show the string values    
  9. for (NSString *str in array2)  
  10.   NSLog(@"--%@", str); 

Here, array2 is always empty because:

Select DrinkArray. plist, ctrl + click (or right-click, if there is a mouse) open as-> source code, the result is as follows:

 
 
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <!DObjective-CTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
  3. <plist version="1.0"> 
  4. <dict> 
  5.       <key>Root</key> 
  6.        <array> 
  7.          <string>Firecracker</string> 
  8.       <string>Lemon Drop</string> 
  9.        <string>Mojito</string> 
  10.        </array> 
  11. </dict> 
  12. </plist> 

Solution: manually modify it:

 
 
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <!DObjective-CTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
  3. <plist version="1.0"> 
  4.      <array> 
  5.                <string>Firecracker</string> 
  6.              <string>Lemon Drop</string> 
  7.               <string>Mojito</string> 
  8.      </array> 
  9. </plist> 

Summary: reading from XCode 4Plist FileI hope this article will help you!

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.