core-data

How to fetch a range of items from the database

北战南征 提交于 2020-01-16 09:04:04
问题 How do I fetch, say, item 7 000 to 7 999 in my SQLite table with around 100 000 items? The normal fetch returns to much to work with, and I rather fetch it little by little: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Log" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&err]; // here fetchedObjects holds around 100

Core Data on multiple threads

拜拜、爱过 提交于 2020-01-16 08:55:47
问题 I have a Core data managedObjectContext on the main thread, then I created another managedObjectContext on the background thread. If there is a change on the background thread I just call the ManagedObjectDidSave notification. My question is if I made a change on the mainthread, I also need to tell the managedObjectContext on the background thread right? I have user a user data class which gets and sets userdata on both main and background thread. I should pass the managedobject of the thread

Shipping a pre populated SQLite DB within the app. Path of the DB on startup

邮差的信 提交于 2020-01-16 08:55:16
问题 Maybe the title of the question is not very self-explanatory but I don't know how to summ it up. I'm finishing an App which is basically a DB. I will ship a DB within the App. Everything works well but now I came to the problem. When the App is installed, it needs to create the database on the device. So, I dragged the DB to the "Supporting Files" folder in my Xcode project (still Xcode 4.1, by the way). I went to the AppDelegate.m file and looked for the (NSPersistentStoreCoordinator *

Restkit + Core Data: Inserts duplicate values in a UITableView on every app launch

*爱你&永不变心* 提交于 2020-01-16 01:01:19
问题 Following AlexEdge Tutorial I have encountered the following behavior. I can provide code as requested since there are many lines and I'm not really sure where to look. Basically, it "works" in the sense that the data is properly loaded into the UITableView, but after stopping and starting up the simulator, it inserts new duplicate rows in each section. I figured this would have something to do with caching but I am following the above tutorial pretty closely and I've set the

How do I do this NSPredicate code?

限于喜欢 提交于 2020-01-16 00:56:08
问题 I'm having trouble with NSPredicate. I have a core data object called Entry, which contains an NSDate called creationDate. I want to compare this to the variable I have called date. I'm using an NSDate category to pull out the individual year of both objects, and a core data category to perform a predicate on all Entry objects in my core data store. [Entry allForPredicate:[NSPredicate predicateWithFormat:@"creationDate.year == %i", date.year]]; I think this is wrong, as it's not giving me the

“Core Data could not fulfill a fault” for objects that were created in the appDelegate managedObjectContext on the main thread

笑着哭i 提交于 2020-01-16 00:43:06
问题 I mistakenly created a group of objects on a background thread, which created a new managedObjectContext in which the objects were saved. This resulted in numerous "Core Data could not fulfill a fault" crashes in my live app. Please note - I am not trying to delete these objects - it is a problem with the way they were created, when I try to save them again afterwards in the app delegate (main) context on the main thread. The thing that is confusing is that I am seeing this error for other

Ordering core data objects inside a table view section

本秂侑毒 提交于 2020-01-16 00:39:11
问题 I am using NSSortDescriptors to order core data objects and create table view sections depending on a date attribute. Using this kind of SortDescriptor, the table view sections are ordered as expected, but the rows inside the sections are also ordered by the same date attribute. Is there a way to have another ordering system inside each section? I guess the main problem is that core data stores date objects with date+time values, that way there are no objects with exactly the same date value.

How to group fetched result from Core Data, iOS dev

徘徊边缘 提交于 2020-01-15 23:03:23
问题 I have a core data with an Entity called "Expense", its like: Entity: "Expense" Attributes: "Date", "Category", "Amount".......... My question is that is it possible to fetch how many expenses by year or year-month? I know if the fetch is based on time period or category, I can use NSPredicate to filter the fetched result. But the "Date" attribute in my mind should be seperated by year and month, so I can group them as in SQL query. Is it possible to do that directly in fetch? Otherwise the

core data get data from current week

亡梦爱人 提交于 2020-01-15 19:11:10
问题 I have a core data context with objects that have a date stored in them. I would like to get the data for only the current week (Monday to Sunday) in that order. I am not looking for the last 7 days. The date could be the one stored inside the entity or the data of when the object was added to core data (they are the same). I can use a predicate with a start date and end date like this: NSPredicate *weekPredicate = [NSPredicate predicateWithFormat:@"((date > %@) AND (date <= %@)) || (date =

NSFetchedResultsControllers in different view controllers updating each other?

为君一笑 提交于 2020-01-15 11:57:29
问题 Ok I get more and more general with this question, since I've noticed several lags in my app due to this. I've noticed the problem with reordering, but it happens in other places as well. I have a CoreDataViewController class which all my table view controllers subclass. And in this class I basically have all NSFetchedResultsController delegate methods as they are in the apple docs. Then I've tried to find out how often changes are noticed by this NSFetchedResultsController to find out where