core-data

How do you restart a query using NSFetchedResultsController

I'm finishing up the Core Data tutorial, and it suggests trying to convert to using a NSFetchedResultsController. So I've got it so that I can query the existing data, but when I add a row at the beginning, tableView:cellForRowAtIndexPath calls NSFetchedResultsController.objectAtIndexPath, but that still returns the old zeroth object in...

How do I test for the existence of any object of a given entity type?

I'm successfully using Core Data in my project and have code that looks like this to control an icon state: -(BOOL)messageItemEnabled; { // If there are items in the message queue, it's enabled NSSet *messageSet = [moc fetchObjectsForEntityName:@"Message" withPredicate:nil]; return [messageSet count] > 0; } All I really need to know ...

Core Data Primary Key

This may seem stupid, but I still couldn't figure out how to mark a attribute as a primary key in the xcdatamodel file. My persistent storage is sqlite file. Can anyone help me? In that case, how can I "validate" a ID to be unique? Should I write a validation method or something? ...

How do I override NSError presentation when bindings is involved?

One thing I've always had trouble with in Cocoa Bindings has been error presentation, for example when the user types the wrong value into a text field with a formatter attached. Normally I would override willPresentError: somewhere in the responder chain, but my problem is the NSError objects created by the Bindings system doesn't conta...

Producer Consumer Issue with Core Data

I've a Core Data application. In the producer thread, I pull data from a web service and store it in my object and call save. My consumer object is a table view controller that displays the same. However, the app crashes and I get NSFetchedResultsController Error: expected to find object (entity: FeedEntry; id: 0xf46f40 ; data: ) in s...

CoreData equivalent of sum...group by

I have the following pseudo-SQL schema: table flight id int primary key date timestamp aircraft_id int (foreign key to aircraft.id) table flight_component flight_id int (foreign key to flight.id) component_id int (foreign key to component.id) duration double If I convert this to using CoreData, is there an equivalent way ...

Core Data NSPredicate for relationships.

My object graph is simple. I've a feedentry object that stores info about RSS feeds and a relationship called Tag that links to "TagValues" object. Both the relation (to and inverse) are to-many. i.e, a feed can have multiple tags and a tag can be associated to multiple feeds. I referred to http://stackoverflow.com/questions/844162/how...

Provide Base Data for Core Data Application?

I'm working on a Core Data app (for iPhone 3.0, though I don't think that really makes a difference here) and it will need to ship with a "starter" database filled with data. With SQLite, I would just have the App copy the populated database from the bundle into the App's documents directory on first launch and then load that database - ...

NSFetchRequest - can it return an array of properties?

Hello, Unless I have missed something in the documentation, I can't see if it is possible to execute an NSFetchRequest so that it returns an array of properties of objects, instead of the objects themselves. For example, I have: @interface SaleDate { NSDate *open; NSDate *close; Sale *sale; } I want to query something like "clos...

NSArray to Core Data items

Hey, I have an method that reads an xml file and stores the xml nodes at a certain XPath-path in an NSArray called *nodes. What I want to do is take each one of the items in the array and add it to a core data entity called Category with the attribute of "name". I have tried a number of different ways of creating the entity but I'm no...

Core Data: Is it possible to build a desktop app to create the data model for an iPhone app with Core Data?

Hi, I'm currently in the process of deciding whether or not to use Core Data for managing the data in my iphone application. The application involves putting together a fairly sizeable library of content which needs to be localised and has a fair few relationships. One benefit I thought of using core data would be that I could perhaps b...

How would you make a text cell in a an Outline View show how many children the parent row has?

How would you make Rows that are the Top Parent in an Outline View (which is connected to a NSTreeController) display how many children it has in a Text Cell? If this is a bit confusing here is a Picture of what I mean. I am talking about the number to the right of one of the rows in the circle, which is displaying how many childre...

CoreData - how to create a subclass of a subclass of NSManagedObject (Generation Gap pattern)

I'm sure this must be a stupid question, but I've scoured the interwebbings and can't find the answer. Plenty of people talk about using the Generation Gap pattern, in which you have an NSManagedObject subclass that is generated from your model, and then subclass that to add transient properties and behaviours. The benefit of this is tha...

Core Data: Query objectIDs in a predicate?

Hi there, I am fetching a set of objects from a Core Data persistent store using a fetch request and a predicate. My current predicate simply checks whether an attribute is >= a certain value. This all works great, except that I want to finally exclude any objects that are currently held in an array. I basically need to be able to excl...

Update bound dictionary based on NSTextFieldCell's edited value

I'm working on porting some ancient code (10.2 era) from NSCoding/plist based archiving to using Core Data. I have an NSOutlineView with a custom NSTextFieldCell. The outline view is bound to an NSTreeController to provide the data. The bindings model looks like this: NSTreeController: Managed Object Context -> Controller.managedObjec...

Using core data, is the a way to automatically delete an entity when a to-many relationship falls below the min-count?

I have a core data model which includes an entity with a to-many relationship. I have set the relationship to non-optional and set the 'min count' to one. However, I can't work out a way of acting on this rule once it has been breached. Ideally I'd just like the entity deleted... but I can't figure out a way to do this automatically, or ...

How would you make the text in a checkbox cell be able to be edited?

How would you make the text in a check box cell able to be edited like in a text cell instead of it just checking the Checkbox? The thing is that the Checkbox is Boolean in the Core Data Model and the Text is a String, so I don't know how I would make this work. ...

CoreData design pattern: persisting a single object of many -or-how many NSPessistentObjectContexts should I have?

I'm converting an app from SQLitePersistentObjects to CoreData. In the app, have a class that I generate many* instances of from an XML file retrieved from my server. The UI can trigger actions that will require me to save some* of those objects until the next invocation of the app. Other than having a single NSManagedObjectContext for...

How do I localise the default value of attribute in a Core Data Entity

If I was creating an entity with a non-optional string attribute called, say, "name", I would put "Untitled" as the default. How could I localise this default value? I could subclass the entity and and use NSLocalizedString in awakeFromInsert to do this. But I was wondering if there was another way. Edit: If this is the only way, then...

Default dataset for Core Data based iPhone application

I am writing an iPhone 3.0 application that uses Core Data to persist the model. I'd like the application to be installed with a default dataset. When developing for iPhone < 3.0 I used an SQL script to initialize a database prior to running a build and then deployed the prepared .sqlite file as an application resource. What's the best a...