我有一个看起来像这样的plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
Translations
-->
<plist version="1.0">
<array>
<dict>
<key>English</key> <string>Hello Mrs./Mr./Miss.</string>
<key>French</key> <string>Bonjour Madame / Monsieur / Mademoiselle.</string>
<key>Spoken</key> <string>Boh(n)-zhoor mah-dahme/ muh-syuhr/ mah-dah-mwa-sell.</string>
</dict>
<dict>
<key>English</key> <string>Excuse me.</string>
<key>French</key> <string>Pardon.</string>
<key>Spoken</key> <string>Par-doh(n).</string>
</dict>
<dict>
<key>English</key> <string>Do you speak English?</string>
<key>French</key> <string>Parlez-vous anglais?</string>
<key>Spoken</key> <string>Par - lay vooz ah(n)-glay?</string>
</dict>
</array>
我希望能够在plist中搜索“借口”或“你好”等词语。有人知道如何在这样的plist中搜索术语的存在吗?
答案 0 :(得分:0)
首先将plist加载到内存中。你有一系列词典,所以你应该使用NSArray
NSArray *translations = [[NSArray alloc] initWithContentsOfFile:filePath];
现在只需使用NSArray
过滤方法即可获得所需内容。
NSArray *matches = [translations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self CONTAINS[cd] %@", searchTerm]];