1

I'm trying to use a deeply nested data structure and NSPredicate to filter that data.

I have a plist file like this:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>images-ipad</key>
        <array>
                <dict>
                        <key>categories</key>
                        <array>
                                <string>standard</string>
                        </array>
                        <key>name</key>
                        <string>Default</string>
                        <key>plist</key>
                        <string>cardSheet.plist</string>
                        <key>png</key>
                        <string>cardSheet.png</string>
                </dict>
                <dict>
                        <key>categories</key>
                        <array>
                                <string>standard</string>
                        </array>
                        <key>name</key>
                        <string>Optional</string>
                        <key>plist</key>
                        <string>cardSheet.plist</string>
                        <key>png</key>
                        <string>cardSheet.png</string>
                </dict>
                <dict>
                        <key>categories</key>
                        <array>
                                <string>christmas</string>
                                <string>holiday</string>
                                <string>standard</string>
                        </array>
                        <key>name</key>
                        <string>christmas</string>
                        <key>plist</key>
                        <string>cardSheet.plist</string>
                        <key>png</key>
                        <string>cardSheet.png</string>
                </dict>
        </array>
</dict>
</plist>

Which I load into an NSDictionary via dictionWithContentsOfFile.

I then want to get the elements of the array images-ipad that are in the category 'standard' via NSPredicate. I think this is possible, but I've not been able to accomplish it, and the docs don't seem to cover nested data structures.

So, I've tried this:

NSPredicate *getcat = [NSPredicate predicateWithFormat:@"ANY images-ipad.categories == 'holiday'"];
NSArray *res = [[dict objectForKey:@"images-ipad"] filteredArrayUsingPredicate:getcat];

but it does not return any elements, which brings me to stackoverflow. Thanks in advance.

1 Answer 1

4

Since you're filtering the result of [dict objectForKey:@"images-ipad"], you shouldn't include that string in the key path of the predicate, as it's basically equivalent to looking up images-ipad.images-ipad.categories, which doesn't exist.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.