Thursday, 15 March 2012

ios - Filter CoreData (Parent entity and child entity) -



ios - Filter CoreData (Parent entity and child entity) -

two days have been trying filter coredata , i'm still stuck. model:

users < --- >> sessions

i managed create relationship between new session , specific user. managed list of users display them in tableview code :

nsfetchrequest *request = [[nsfetchrequest alloc]init]; nsentitydescription *usersdescription= [nsentitydescription entityforname:@"users" inmanagedobjectcontext:_managedobjectcontext]; [request setentity:usersdescription]; nserror *error = nil; nsmutablearray *mutablefetchresults = [[_managedobjectcontext executefetchrequest:request error:&error]mutablecopy]; if(mutablefetchresults == nil) { //handle error } usernamedatamutablearray = [[nsmutablearray alloc]init]; (int = 0; i< [mutablefetchresults count]; i++) { users* users = (users *) [mutablefetchresults objectatindex:i]; [usernamedatamutablearray insertobject: [users username] atindex:i]; }

now when touch cell called "username1", display new tableview. display in tableview username1 sessions.

so question is: how can filter sessions retrieve these belong username1?

there no filter required.

when force new view controller hand off instance of users selected. in new view controller inquire instance of users sessions instances associated it.

nsset *sessionsset = [myuser valueforkey:@"sessions"];

you can utilize property if have subclasses set up.

this point of core data. object graph , relationships properties on object instance. phone call appropriate method.

i suggest reading book on core info clear lot of issues having these fundamental concepts.

additional comments

entities should not named in plural. entities should called user , session instead of plural form. name of relationship points to-many should plural , name points to-one should singular. helps code clarity , maintainability. plural tends indicate collection of objects instead of single object have now.

ios core-data filter

No comments:

Post a Comment