Question

I have a plist that looks like this:

<?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>

I want to be able to search the plist for terms like "excuse" or "hello." Does anybody know how to search for the existence of terms in such a plist?

Was it helpful?

Solution

Start by loading the plist into memory. You have an array of dictionaries so you should use NSArray

NSArray *translations = [[NSArray alloc] initWithContentsOfFile:filePath];

Now just use NSArray filtering methods to get what you want.

NSArray *matches = [translations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self CONTAINS[cd] %@", searchTerm]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top