ios - How To Match NSUserDefaults and CoreData Attribute and Get Data if both are same -


here have entity named cliptable fetching clip related information of users here want fetch clip information particular user logged in,for have stored user_id using nsuserdefaults. , clip table has attribute named created_by_user, userid of particular user stores clip. using created_by_user attribute , user_id nsuserdefaults want check whether both same. , if both same clip record of particular user only. below code able show clip record of user in tableview using nsfetchresultcontroller. want records particular user only. hard time doing this. appreciated.

user_id [nsuserdefaults standarduserdefaults] stringforkey:@"userid"]

-(void)fetch:(nsstring*)catgeory :(bool)all{  appdelegate *delegate = [[uiapplication sharedapplication] delegate]; self.managedobjectcontext = delegate.managedobjectcontext; nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] initwithentityname:@"cliptable"];  // add sort descriptors [fetchrequest setsortdescriptors:@[[nssortdescriptor sortdescriptorwithkey:@"modifieddate" ascending:no]]];  //_fetchedresultscontroller=nil; // initialize fetched results controller self.fetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:self.managedobjectcontext sectionnamekeypath:nil cachename:nil];  if (all==no) {     [fetchrequest setpredicate:[nspredicate predicatewithformat:@"(page_categorisation == %@)",catgeory]]; }  [fetchrequest setfetchbatchsize:0]; //  [fetchrequest setfetchlimit:10]; // configure fetched results controller [self.fetchedresultscontroller setdelegate:self];  // perform fetch nserror *error = nil; [self.fetchedresultscontroller performfetch:&error];  if (error) {     nslog(@"unable perform fetch.");     nslog(@"%@, %@", error, error.localizeddescription); } } 

here simple solution use predicate fetch clips of logged in user. value of current logged in user nsuserdefaults in currentloggedinuser , pass below.

nsstring *predicatefrmt = @"created_by_user == %@ ; nspredicate *predicate = [nspredicate predicatewithformat: predicatefrmt, currentloggedinuser]; fetchrequest.predicate = predicate; 

for category can use ,

[fetchrequest setpredicate:[nspredicate predicatewithformat:@"(page_categorisation == %@ , created_by_user == %@ )",catgeory,currentloggedinuser]]; 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -