ios - NSFetchRequest on a specific store -
i starting use multiple persistent stores core data. wrote following code:
- (nsuinteger)countentity:(nsstring*)entityname withpredicate:(nspredicate*)predicate onstore:(nsstring*)configname { nsfetchrequest *request=[[nsfetchrequest alloc] init]; if (predicate) [request setpredicate:predicate]; nserror *error=nil; [request setentity:[nsentitydescription entityforname:entityname inmanagedobjectcontext:context]]; [request setaffectedstores: [nsarray arraywithobject:[[configurdico objectforkey:configname] objectforkey:@"store"]]]; nsuinteger count=[context countforfetchrequest:request error:&error]; // problematic line. return count; }
but following message, on line problematic line un debugger.
2014-12-06 02:56:10.932 theapp[1501:76002] -[nsurl executerequest:withcontext:error:]: unrecognized selector sent instance 0x1757df50
what doing wrong?
for reference have following method, previous one, working perfectly:
- (nsuinteger)countentity:(nsstring*)entityname withpredicate:(nspredicate*)predicate { nsfetchrequest *request=[[nsfetchrequest alloc] init]; if (predicate) [request setpredicate:predicate]; nserror *error=nil; [request setentity:[nsentitydescription entityforname:entityname inmanagedobjectcontext:context]]; nsuinteger count=[context countforfetchrequest:request error:&error]; return count; }
that makes me think, since line added, must using setaffectedstores: wrong way.
your context
variable of wrong type (nsurl instead of nsmanagedobjectcontext). make sure set core data stack correctly.
Comments
Post a Comment