nsfetchrequest

NSFetchedResultsController with section names

久未见 提交于 2019-12-24 11:12:33
问题 Scenario: I have an expense tracking iOS Application and I am storing expenses from a expense detail view controller into a table view (with fetched results controller) that shows the list of expenses along with the category and amount and date. I do have a date attribute in my entity "Money" which is a parent entity for either an expense or an income. My Question: What I want is to basically categorize my expenses/incomes for a given week, a month, or year and display it as the section

Sort/Filter NSFetchRequest how to write sort descriptor taht will use current date?

☆樱花仙子☆ 提交于 2019-12-24 07:37:27
问题 I'm storing in Core Data 2 date properties, one is expire date and second is "amber" date (the date that is X weeks before expire date). I want to sort results in following way: items before the amber date - (green) now < amber items after amber date but before expire date - (amber) amber <= now < expire items on or after expire date - (red) expire <= now Can you help me with that? UPDATE After more research I've found that I could fetch results unsorted, put it in the array and sort the

How to change managed object class name before fetching

依然范特西╮ 提交于 2019-12-24 04:32:12
问题 I have a Swift app that uses CoreData. I created List entity with class MyAppTarget.List . Everything is configured properly in .xcdatamodeld file. In order to fetch my entities from persistent store, I am using NSFetchedResultsController : let fetchRequest = NSFetchRequest() fetchRequest.entity = NSEntityDescription.entityForName("List", inManagedObjectContext: managedObjectContext) fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "name", ascending: true) ] let fetchedResultsController

How to change managed object class name before fetching

我是研究僧i 提交于 2019-12-24 04:32:02
问题 I have a Swift app that uses CoreData. I created List entity with class MyAppTarget.List . Everything is configured properly in .xcdatamodeld file. In order to fetch my entities from persistent store, I am using NSFetchedResultsController : let fetchRequest = NSFetchRequest() fetchRequest.entity = NSEntityDescription.entityForName("List", inManagedObjectContext: managedObjectContext) fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "name", ascending: true) ] let fetchedResultsController

NSFetchRequest returns old data even though the database is updated

試著忘記壹切 提交于 2019-12-23 20:33:24
问题 I'm working on a Multi-threaded application that uses Coredata. When i save some data on one thread it goes to the database but when I try to fetch it from a different thread once the data is saved to the database, the fetch request returns the old data. Any suggestions on how to fix this? 回答1: This was an issue due to the MOC merge policy. I have used NSMergeByPropertyObjectTrumpMergePolicy earlier and switching to NSMergeByPropertyStoreTrumpMergePolicy fixed the issue. Keep in mind, this

Core Data - complex fetch

倾然丶 夕夏残阳落幕 提交于 2019-12-23 03:37:13
问题 This is my core data model: Conference ========== name events (to-many relationship to Event object) Event ====== date type (int - private=0, public=1) conference (to-one relationship to Conference object) So conference can have many events, and event has only one conference: Conference <------>> Event I have a complex fetch that I'm not sure how to do, this is what I need: The 3 top conferences with the most public events AND meet the basic conditions, meaning: 1. conference has at least 1

Is it possible to have Core Data sort the “many” part of a To-Many relationship during a fetch request?

自闭症网瘾萝莉.ら 提交于 2019-12-22 17:59:32
问题 I'm using Core Data to cache a decent amount of information, and I have a To-Many relationship set up among my managed objects. Naturally I use an NSFetchRequest to fetch an array of the singular side of that relationship. However, I populate a UITableView using the the "many" side of the relationship, and I'd like it to be sorted alphabetically when I pull the data. If I'm not being clear, here's an example: "employee" and "boss" are both NSManagedObjects in a To-Many relationship - each

Saving and Deleting NSManagedObject & NSManagedObjectContext

好久不见. 提交于 2019-12-22 10:13:44
问题 Three Questions but they are all related. If you like I can divide them into three questions so that you can more credits. Let me know if you'd like for me to do that. I have the following code that allows me to access NSManagedObject self.managedObjectContext = [(STAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; NSError *error; NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:[NSEntityDescription entityForName:@"LetsMeet"

Is it possible to sort by subclasses in an `NSFetchRequest` without adding additional attributes?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 04:38:18
问题 I want to group the results of a NSFetchRequest by entity. The entities all share the same abstract parent. For example: animal | |-cat | |-dog The NSFetchRequest has includesSubentities set TRUE and entity set to animal . It is possible to set sectionNameKeyPath of NSFetchedResultsController to entity.name but it is not possible to do the same with the sortDescriptors of the NSFetchRequest due to the fact that the sortDescriptors are applied to the stored attributes (i.e. data in the

Core Data Performance: NSPredicate comparing objects

匆匆过客 提交于 2019-12-22 04:17:21
问题 If my Author NSManagedObject model has a authorID attribute (determined by the server), will an NSFetchRequest perform better if the NSPredicate filters by authorID rather than the complete Author object? Let's say I'm fetching all Book NSManagedObject s by a certain author . Which predicateFormat is better? [NSPredicate predicateWithFormat:@"author = %@", anAuthor] or [NSPredicate predicateWithFormat:@"author.authorID = %@", anAuthor.authorID] What's the best way to profile this? I have Core