Ste*_*fan 6 iphone xcode objective-c plist
我有一个像这样的plist:
<dict>
<key>11231654</key>
<array>
<string>hello</string>
<string>goodbye</string>
</array>
<key>78978976</key>
<array>
<string>ok</string>
<string>cancel</string>
</array>
Run Code Online (Sandbox Code Playgroud)
我用这个加载了plist:
NSString *path = [[NSBundle mainBundle] pathForResource:
@"data" ofType:@"plist"];
// Build the array from the plist
NSMutableArray *array3 = [[NSMutableArray alloc] initWithContentsOfFile:path];
Run Code Online (Sandbox Code Playgroud)
我怎样才能访问我的plist的每个元素?我想在plist中搜索匹配的键,而不是搜索其子项.我怎样才能做到这一点?有什么建议吗?
请提前!
数组已编入索引.如果要访问a中的第一个对象,NSArray则执行以下操作:
id someObject = [array objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
如果你知道对象类型,你可以这样做:
NSString *myString = [array objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
编辑:您需要使用a NSDictionary来获取您拥有的数据 - 请注意它以<dict>标记开头,而不是<array>标记(尽管有数组作为值).
NSString *path = [[NSBundle mainBundle] pathForResource:
@"data" ofType:@"plist"];
// Build the array from the plist
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *value = [dict valueForKey:@"11231654"];
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用阵列执行任何操作.
| 归档时间: |
|
| 查看次数: |
7249 次 |
| 最近记录: |