Search code examples
objective-crealmnspredicate

NSPredicate query for a Realm object


Could someone please help me construct a realm query to search for a video(s) of a particular entryid value, for extra points a second query that would find both videos by their entryids ?

Thank you!

Video {
    nid = 1;
    video_title = OK;
    video_description = Description {
        value = Description;
    };

    video_kaltura = Kaltura {
        entryid = 0_abababa3;
        mediatype = 1;
    };
}

Video {
    nid = 2;
    video_title = OK;
    video_description = Description {
        value = Description;
    };
    video_kaltura = Kaltura {
        entryid = 0_cdcdcdc3;
        mediatype = 1;
    };
}

I've tried things like:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"video_kaltura['entryid'] CONTAINS[c] '0_abababa3'"];
RLMResults *test = [Video objectsWithPredicate:pred];

and their variations to no avail.


Solution

  • NSPredicate uses key paths to traverse properties (object.someProperty.otherProperty).

    Based on your example data, you'd want a predicate like video_kalutra.entryid == '0_abababa3'.