ios - How To Format NSPredicate when doing an "IN" search with Coredata and NSFetchRequest -


i have simple fetch request want execute. 1 of entities has attribute called smartcollectionids , of type transformable. use attribute store nsarray of simple strings. in code use nsfetchedresultscontroller populate tableview. predicate im using follows:

predicate=[nspredicate predicatewithformat:@"smartcollectionids!=nil && (%@ in smartcollectionids)",@"87f173a5-863d-4ece-9673-a61d8f1e01fc-6285-000009a9cbaf3290"]; 

however causes crash, @ pint when perform fetch. however, if first use fetch load objects array, , filter them out above predicate, app not crash, , results expected. this code below not work

-(void) tryto { nsentitydescription *entity = [nsentitydescription entityforname:@"tweetary" inmanagedobjectcontext: [[chubbyeyetwitterengine sharedinstance] getmanagedobjectcontextforuse]];  nspredicate *predicate;  predicate=[nspredicate predicatewithformat:@"smartcollectionids!=nil && (%@ in smartcollectionids)",@"87f173a5-863d-4ece-9673-a61d8f1e01fc-6285-000009a9cbaf3290"];  nssortdescriptor *secondarysortkey = [[[nssortdescriptor alloc] initwithkey:@"created_at" ascending:false] autorelease];  nsfetchrequest *request = [[[nsfetchrequest alloc] init] autorelease] ; [request setentity:entity]; [request setpredicate:predicate]; [request setsortdescriptors:[nsarray arraywithobjects:                              secondarysortkey                              ,nil]]; [request setfetchlimit:30];  //30   nserror *error;  nsarray *results = [[[chubbyeyetwitterengine sharedinstance] getmanagedobjectcontextforuse] executefetchrequest:request error:&error];  if (error != nil) {      nslog(@"results %d",[results count]);  }else{     nslog(@"findallobjectsincontext error %@",error);  } 

}

but works

  nsarray *tweets = [tweetary findallobjectsincontext:[[chubbyeyetwitterengine sharedinstance] getmanagedobjectcontextforuse]];  nslog(@"before filter count %d",[tweets count]);  predicate=[nspredicate predicatewithformat:@"smartcollectionids!=nil && (%@ in smartcollectionids)",@"87f173a5-863d-4ece-9673-a61d8f1e01fc-6285-000009a9cbaf3290"];  predicate=[nspredicate predicatewithformat:@"smartcollectionids!=nil && (%@ in smartcollectionids)",@"87f173a5-863d-4ece-9673-a61d8f1e01fc-6285-000009a9cbaf3290"];  nsarray *bnames = [tweets filteredarrayusingpredicate:predicate];  nslog(@"final results %d",[bnames count]);    + (nsarray *)findallobjectsincontext:(nsmanagedobjectcontext *)context;   {    @synchronized(self){  nsentitydescription *entity = [self entitydescriptionincontext:context]; nsfetchrequest *request = [[[nsfetchrequest alloc] init] autorelease]; [request setentity:entity]; nserror *error = nil; nsarray *results = [context executefetchrequest:request error:&error]; if (error != nil) {     //handle errors     //nslog(@"findallobjectsincontext error %@",error); } return results;   }  } 

in nutshell, need fetch predicate work when using nsfetchedresultscontroller instead of first loading objects array, , applying filter predicate. can point me in right direction/ figure out why predicate works after load unfiltered data set array?

a core data fetch request predicate translated sqlite query , executed on sqlite level. transformable array stored blob in sqlite database, therefore treating array in fetch request not work.

if fetch elements first, blob transformed array when property accessed. therefore filtering array of fetched objects works expected.

i don't think there workaround. cannot filter on transformable properties in fetch request.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -