Note that there are some explanatory texts on larger screens.

plurals
  1. PONSManagedContext takes very long time to persist
    primarykey
    data
    text
    <p>My application has a UITableViewController which has a list of cells representing names of cities. When a user clicks a cell, the application will change the cell accessoryType to UITableViewCellAccessoryCheckmark and save the text value of the cell (city name) into the persisted store. However, I found that every time I click the cell, it requires at least 10 seconds to actually store the data into the Persistent Store. Any idea why this happens? Instead of saving the data immediately, why it takes so long to persist?</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cityName = [self.citySettingModel nameOfCityAtIndex:indexPath.row OfCountryAtIndex:self.countryIndex]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { cell.accessoryType = UITableViewCellAccessoryNone; [[self.citySettingModel worldbikesCoreService] removeCity:cityName]; } else { cell.accessoryType = UITableViewCellAccessoryCheckmark; [[self.citySettingModel worldbikesCoreService] addCity:cityName toCountry:self.countryName]; } } </code></pre> <p>The code for create a City and Country objects are in a different class</p> <pre><code>- (City *) addCity:(NSString*) cityName toCountry:(NSString*) countryName { NSManagedObjectContext *context = [self.delegate managedObjectContext]; Country *country = [self.countryDAO addCountry:countryName inManagedObjectContext:context]; City *city = [self.cityDAO addCity:cityName inManagedObjectContext:context]; [country addCitiesObject:city]; return city; } - (City*) addCity:(NSString*) cityName inManagedObjectContext:(NSManagedObjectContext *)context { NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"City"]; fetchRequest.predicate = [NSPredicate predicateWithFormat:@"cityName = %@", cityName]; NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"cityName" ascending:YES]; fetchRequest.sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; NSError *error; NSArray *matches = [context executeFetchRequest:fetchRequest error:&amp;error]; if (error) NSLog(@"error when retrieving city entities %@", error); City *city; if (!matches || [matches count] &gt; 1) ; else if ([matches count] == 0) { city = [NSEntityDescription insertNewObjectForEntityForName:@"City" inManagedObjectContext:context]; city.cityName = cityName; } else city = [matches lastObject]; return city; } </code></pre>
    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.
    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