nsfetchedresultscontroller

NSFetchedResultsController fetch request - updating predicate and UITableView

两盒软妹~` 提交于 2019-12-07 13:54:49
问题 In my iPhone Core Data app I have it configured in a master-detail view setup. The master view is a UITableView that lists objects of the List entity. The List entity has a to-many relationship with the Task entity (called "tasks"), and the Task entity has an inverse to-one relationship with List called "list". When a List object is selected in the master view, I want the detail view (another UITableView) to list the Task objects that correspond to that List object. What I've done so far is

How to get DateSectionTitles using FetchedResultsController in Swift 4

我与影子孤独终老i 提交于 2019-12-07 12:22:47
问题 I am using FRC and I want to create sections that groups data according to date (DD MMMM)! Each task has a date and i am using that date and formatting it for the section header titles. I am using Apple's sample code that they have provided in Objective C and converted it in to swift. Here is the code: import UIKit import CoreData class completedNotes: NSManagedObject { @NSManaged var cNote: String @NSManaged var cPriorityColor: UIColor @NSManaged var cDate: Date } extension completedNotes {

Save order of UITableViewCells

社会主义新天地 提交于 2019-12-07 10:45:18
问题 I added the option in my tableview to sort/reorder cells. I used this tutorial: http://www.ioscreator.com/tutorials/reordering-rows-table-view-ios8-swift. Now I'd like to ask how I can save the sorting/order of the cells? I also use Core Data and the fetchedResultsController . 回答1: Add an extra attribute to your Core Data model object that is used to store the sort order. For example, you could have an orderIndex attribute: class MyItem: NSManagedObject { @NSManaged var myOtherAttribute:

NSFetchedResultsController and Entity Inheritance

为君一笑 提交于 2019-12-07 09:59:24
问题 I have a parent entity in my model Event. And two child entities: Birthday, Anniversary. I'm using the entity inheritance feature built into Core data such that birthday and anniversary's parent object is Event. So I do a fetch using the following: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext]; [fetchRequest setEntity:entity]; // Set the batch size to a

Deleting last row in a section -> crash, using NSFetchedResultsController

被刻印的时光 ゝ 提交于 2019-12-07 08:14:07
问题 I'm using NSFetchedResultsController. Previously I had a similar issue when the database has no entries for the tableview but then one is created, I turned out there has to be at least one section, so I fixed that. But now it crashes when I have for example two sections, each with one row and I delete one row, so section should be gone -> crash. It says that the number of sections before the update (2) is not equal to the number deleted (0). - (NSInteger)numberOfSectionsInTableView:

Needed clarifications for NSFetchedResultsController and NSFetchedResultsControllerDelegate

可紊 提交于 2019-12-07 03:27:23
Within SO there are a lot of questions/replies about NSFetchedResultsController and delegate. Sometimes the delegate fires, sometimes not. And since Core Data is quite complex argument is quite difficult to understand what is going on without spending a lot of time on it. In addition, the documentations says that there are several problems but it does not list them. There are several known issues and behavior changes with NSFetchedResultsController on various releases of iOS. Hence, I need some clarifications about the behavior of such a class. In particular, from the documentation there is

NSSortDescriptor to sort by number of items in Core Data To-Many Relationships

时间秒杀一切 提交于 2019-12-07 02:04:16
问题 It's a long standing problem when using Core Data to-many-relationships that it is very hard to sort a fetch request using NSSortDescriptor on a Parent entity based on the number of children are in a one-to-many relationship to a Child entity. This is especially useful in combination with a NSFetchedResultsController . Typically initializing the sort descriptor as: NSSortDescriptor *sortByNumberOfChildren = [[NSSortDescriptor alloc] initWithKey:@"children.@count" ascending:NO]; results in an

NSFetchedResultsController: using of NSManagedObjectContext during update brings to crash

空扰寡人 提交于 2019-12-06 21:49:05
Here is the interface of my controller class: @interface ProjectListViewController : UITableViewController <NSFetchedResultsControllerDelegate> { NSFetchedResultsController *fetchedResultsController; NSManagedObjectContext *managedObjectContext; } @end I use following code to init fetchedResultsController : if (fetchedResultsController != nil) { return fetchedResultsController; } // Create and configure a fetch request with the Project entity. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Project"

NSFetchedResultsChangeUpdate fired instead of NSFetchedResultsChangeDelete

狂风中的少年 提交于 2019-12-06 21:45:47
问题 I have a NSFetchedResultsController initiated in the following way: NSEntityDescription *myEntity = [NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:myEntity]; [fetchRequest setFetchBatchSize:10]; [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"wasDeleted == %@", [NSNumber numberWithBool:NO]]]; NSSortDescriptor *sortDescriptor = [NSSortDescriptor

NSFetchedResultsController: The fetched object at index x has an out of order section name

半世苍凉 提交于 2019-12-06 16:09:29
I have three sections in my tableView: Today Upcoming Past When the app launches, the view controller that's launched has an NSFetchedResultsController. If I delete the app and relaunch it in simulator for the first time, it runs great; however, when the date changes, meaning the next day of after, the app gives the error below: 2014-06-29 19:48:35.326 App[37398:4803] CoreData: error: (NSFetchedResultsController) The fetched object at index 4 has an out of order section name ' Upcoming. Objects must be sorted by section name' 2014-06-29 19:48:35.328 App[37398:4803] Unresolved error Error