ios - Predicates and combined filters in core data? -
i'm not using core data currently, i'm switch realm, if i'm sure thing work, vital way application works. have model 2 objects:
message: date - nsdate text - string images - one-to-many > image image: imageurl - string message - many-to-one > image
i have table view displays both images , messages. need know should go @ index path, when uitableview wants know. need able perform query akin to:
"give me ordered list of images , messages, messages sorted date
, images sorted message.date
".
how this?
as far know can't sort mixed array messages , images during coredata fetch request. here 1 possible way:
- fetch messages , images separately
- merge 2 arrays one
- sort 1 array
- (nsarray *)sortedarrayusingfunction:(nsinteger (*)(id, id, void *))comparator context:(void *)context
the function
nsinteger sort(id item1, id item2, void *context) { int v1 = [item1 iskindofclass[message class]]?item1.data:item1.message.date; int v2 = [item2 iskindofclass[message class]]?item1.data:item1.message.date; if (v1 < v2) return nsorderedascending; else if (v1 > v2) return nsordereddescending; else return nsorderedsame; }
Comments
Post a Comment