core-data

Checking an empty Core Data relationship (SQLite)

I have a to-many relationship in my data model, and I'd like to get all the objects that have no corresponding objects in the relationship. For example: Customer -> Purchases I want to get all Customers that have 0 Purchases. I've read somewhere that I could use "Purchases[SIZE] = 0", but this gives me an unsupported function express...

Load data into core-data schema

I am implementing a navigation-based application. The user will drill down to the node of interest. I am using Core Data, mostly because I want to try it out. How do I load the database initially? Should I write custom code that loads the database initially, or is there some tool to do it for me ? ...

What do these errors in the XCode Debugger Mean?

I have 2 errors in XCode and am trying to figure out what they mean. The 1st one: 2009-06-30 18:56:27.998 Spark[4584:10b] Error setting value for key path filterPredicate of object <NSArrayController: 0x1482c0>[entity: group, number of selected objects: 1] (from bound object <NSSearchField: 0x143f20> with object ID 1387 in Nib named...

Filter NSFetchedResultsController for nil value?

I have a NSFetchedResultsController which is fetching objects from a NSManagedObjectContext. These objects have a lastOpened property, which is initially nil and is only set when they are viewed. I want my UITableView to display a list of the most recently opened objects, which I can do by adding a NSSortDescriptor to the NSFetchReque...

How to sort Core Data fetched properties

The Core Data Documentation states that: The fetch request associated with the [fetched] property can have a sort ordering, and thus the fetched property may be ordered. How do I specify the sort descriptors for the fetched property in Xcode's data model editor? I can't find a relevant field anywhere. I'm developing for the iPhon...

Passing a ManagedObjectContext to a second view

I'm writing my first iPhone/Cocoa app. It has two table views inside a navigation view. When you touch a row in the first table view, you are taken to the second table view. I would like the second view to display records from the CoreData entities related to the row you touched in the first view. I have the CoreData data showing up fin...

Setting UITableView headers from NSFetchedResultsController

I have a NSFetchedResultsController which is fetching objects from a NSManagedObjectContext. I'm using the results to populate a UITableView. I'm filtering with these two sort descriptors. NSSortDescriptor *lastOpened = [[NSSortDescriptor alloc] initWithKey:@"lastOpened" ascending:NO]; NSSortDescriptor *titleDescriptor = [[N...

How to implement re-ordering of CoreData records?

I am using CoreData for my iPhone app, but CoreData doesn't provide an automatic way of allowing you to reorder the records. I thought of using another column to store the order info, but using contiguous numbers for ordering index has a problem. if I am dealing with lots of data, reordering a record potentially involves updating a lot...

Delete/Reset all entries in Core Data?

Do you know of any way to delete all of the entries stored in Core Data? My schema should stay the same; I just want to reset it to blank. Edit I'm looking to do this programmatically so that a user can essentially hit a reset button. ...

How to Save multiple values to CoreData

I'm developing an application using Core Data. I want to save multiple values in the database and I used the code snippet: Event *event = (Event *)[NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:managedObjectContext]; [event setLatitude:[NSNumbe...

How to implement/augment Core-Data relationship getter/setter?

I have a fairly involved managed data model which has a central object with many relationships which depend on the values of various attributes. I am importing the initial data into the model using sets of plists, each plist specifying attributes for an entity class and then filling in the relationships based on those attributes. I wan...

I keep on getting "save operation failure" after any change on my XCode Data Model

I started using Core Data for iPhone development. I started out by creating a very simple entity (called Evaluation) with just one string property (called evaluationTopic). I had following code for inserting a fresh string: (void)insertNewObject { // Create a new instance of the entity managed by the fetched results controller. NSMana...

NSFetchedResultsController with sections created by first letter of a string

Learning Core Data on the iPhone... There seems to be few examples on Core Data tables with sections. The CoreDataBooks example uses sections, but they're generated from full strings within the model. I want to organize the Core Data table into sections by the first letter of a last name, ala the Address Book. ... I could go in and cr...

Maintaince of CoreData Application

If you change an anything (entity, relationship, type of attribute etc) in a CoreData model after it has shipped, what is the general process that you have to go through to get the user's store updated for your new model. ...

Copying iPhone CoreData files from one project to another...

I'm trying create 2 apps, one that builds a persistent store, and another one that consumes it. So far I have built one app that uses CoreData to successfully build a database from an XML file. So this project contains the data model, the .h/.m files for the entities, etc. I'm now trying to enable the second app to read that .sqlite f...

Selection of random entries from a Core Data Store

Is there a way to select a fixed number of random entries from a Core Data store? I am just getting started with Core Data and have been stuck on this problem for quite some time. As a last resort, I could query a large selection of entries into memory and then randomly select a fixed number. Also, is there a way to specify custom SQL...

Is there a way to use functions in NSPredicate predicateWithFormat:

I have store with entities that have coords (x, y, z). I want to fetch them by using predicate like @"sqrt(x*x + y*y + z*z) < distance". Is there any way to do this? I've tried to do thi with predicateWithFormat: I even wrote a lot of code that looks like NSExpression * dxExpression = [NSExpression expressionForFunction:@"from:subtr...

Cocoa Core Data effiecient way to count entities!

Hello, i read much about Core Data.. but what is an efficient way to make a count over an Entity-Type (like SQL can do with SELECT count(1) ...). Now i just solved this task with selecting all with NSFetchedResultsController and getting the count of the NSArray! I am sure this is not the best way... thank you ...

Passing objects between managed object contexts

Hi there, I have an iphone app with 2 managed object contexts. One of my contexts deals with a picker, which allows the user to add new records and then select one of those new records. Once the picker is hidden, that managed object context is saved and discarded. I then want to use this selected object in my second managed object con...

How to decrease Core Data's memory usage when cascade deleting large object graphs?

I'm using Core Data to store lists of data. So, there's parent objects with any number of child objects. Core Data does a great job keeping my memory use low while I'm inserting objects and reading but when I do a delete operation the memory spikes way up. When I delete a parent object with ~5000 children the cascade delete uses ~10MB. ...