查询plist是一个字典数组

Arc*_*ian 2 objective-c ios

我有一个有一系列dicts的plist.在dict中有一个名为UID的KEY.我想查询plist,其中UID ="1234"..我将如何搜索?

样品

<array>
   <dict>
      <key>UID</key>
      <string>1234</string>
      <key>name</key>
      <string>bob</string>
   </dict>
   ....
</array>
Run Code Online (Sandbox Code Playgroud)

Dav*_*ong 5

在plist中读取一个字典数组,然后使用filteredArrayUsingPredicate:方法NSArray:

NSString *path = [[NSBundle mainBundle] pathForResource:@"MyInfo" ofType:@"plist"];
NSArray *plistData = [NSArray arrayWithContentsOfFile:path];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"UID = %d", 1234];
NSArray *filtered = [plistData filteredArrayUsingPredicate:filter];
NSLog(@"found matches: %@", filtered);
Run Code Online (Sandbox Code Playgroud)