Note that there are some explanatory texts on larger screens.

plurals
  1. POMysterious core data behavior retrieves empty objects on second fetch
    primarykey
    data
    text
    <p>I'm trying to display a list of objects from Core Data into a UITableViewController. Here is the viewWillAppear of this UITableViewController:</p> <pre><code>- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.landmarks = [[TSDataManager sharedInstance] fetchArrayFromDBWithEntity:@"Landmark" forKey:nil withPredicate:nil]; [self.tableView reloadData]; } </code></pre> <p>And here is the fetchArrayFromDBWithEntity:forKey:withPredicate: implementation:</p> <pre><code>- (NSMutableArray*)fetchArrayFromDBWithEntity:(NSString*)entityName forKey:(NSString*)keyName withPredicate:(NSPredicate*)predicate { NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:self.managedObjectContext]; [request setEntity:entity]; if(keyName != nil){ NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:keyName ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; } if (predicate != nil){ [request setPredicate:predicate]; } NSError *error = nil; NSMutableArray *mutableFetchResults = [[self.managedObjectContext executeFetchRequest:request error:&amp;error] mutableCopy]; if (mutableFetchResults == nil) { NSLog(@"%@", error); } return mutableFetchResults; } </code></pre> <p>When the table first appears, everything is displayed correctly, I have 4 objects coming back from the DB with titles that are correctly displayed in each cell.</p> <p>But whenever I go to another view and come back, the table has four objects alright, but the value of their "title" property is nil!</p> <p>Here is the code of my Landmark class:</p> <pre><code>@interface Landmark : NSManagedObject @property (nonatomic, strong) NSString * title; @end @implementation Landmark @dynamic title; @end </code></pre> <p>And here is how my table cells are constructed, in case it comes from there:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"LandmarkCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; Landmark *landmark = (Landmark *) self.landmarks[(NSUInteger) indexPath.row]; cell.textLabel.text = landmark.title; return cell; } </code></pre> <p>Obviously I'm doing something wrong here, but I seriously can't figure out what.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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