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
- // Path to the plist (in the application bundle)
- NSString *path = [[NSBundle mainBundle] pathForResource:
- @"DrinkArray" ofType:@"plist"];
-
- // Build the array from the plist
- NSMutableArray *array2 = [[NSMutableArray allObjective-C] initWithContentsOfFile:path];
-
- // Show the string values
- for (NSString *str in array2)
- 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:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DObjective-CTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="1.0">
- <dict>
- <key>Root</key>
- <array>
- <string>Firecracker</string>
- <string>Lemon Drop</string>
- <string>Mojito</string>
- </array>
- </dict>
- </plist>
Solution: manually modify it:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DObjective-CTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="1.0">
- <array>
- <string>Firecracker</string>
- <string>Lemon Drop</string>
- <string>Mojito</string>
- </array>
- </plist>
Summary: reading from XCode 4Plist FileI hope this article will help you!