Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes you need to use NSPredicate to get the data related to a specific user. If you are populating a UICollection view then i would recommend also reading up on NSFetchedResultsController.</p> <pre><code>NSFetchRequest *fetchRequestItems = [[NSFetchRequest alloc] init]; NSEntityDescription *entityItem = [NSEntityDescription entityForName:@"Routine" inManagedObjectContext:self.managedObjectContext]; [fetchRequestItems setEntity:entityItem]; User* myUser = //Code for getting current user out of data store based on some paramator [fetchRequestItems setPredicate:[NSPredicate predicateWithFormat:@"userID == %@",myUser]]; //Sort by last edit ordered NSArray *sortDescriptors = [NSArray arrayWithObjects:nil]; [fetchRequestItems setSortDescriptors:sortDescriptors]; NSArray* Routines = [managedObjectContext executeFetchRequest:fetchRequest error:&amp;error]; </code></pre> <p>The thing to note here is you need to set up inverse relationships on your Routine / Exercise objects to compare against the current user in the predicate. Which you have for userID which i presume is an inverse relationship ? </p> <p>So from the comment i take you havent set the inverse relationship so here is a rough example.</p> <p>When making a new User on your store you would get somethign like this:</p> <pre><code>User *thisUser = [NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:self.managedObjectContext]; thisUser.eMail = emailAddress.text; //And any other paras you might have </code></pre> <p>Then when making a routine for that user you would do this:</p> <pre><code>Routine *newRoutine = [NSEntityDescription insertNewObjectForEntityForName:@"Routine" inManagedObjectContext:managedObjectContext]; newRoutine.userId = thisUser; </code></pre> <p>Then make sure to save the managed object to write the changes to the data store. This then links the 2 objects on the routine side, dont forget to link it on the Users side too for a strict inverse relationship.</p> <p>To get the user its exactly like i mentioned above:</p> <pre><code>NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; NSError* error; NSArray* Users = [managedObjectContext executeFetchRequest:fetchRequest error:&amp;error]; </code></pre> <p>If you have 1 user then its the first element in the array, if you have many users then use predicates to find the one based on your FB id. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload