core-data

Is it safe to manipulate objects that I created outside my thread if I don't explicitly access them on the thread which created them?

I am working on a cocoa software and in order to keep the GUI responsive during a massive data import (Core Data) I need to run the import outside the main thread. Is it safe to access those objects even if I created them in the main thread without using locks if I don't explicitly access those objects while the thread is running. ...

setPrimitiveValue:forKey: and to-many relationships

Apple's documentation on -setPrimitiveValue:forKey: is vague in two ways when using it to manage to-many relationships. First they state: If you try to set a to-many relationship to a new NSMutableSet object, it will (eventually) fail. Eventually?! What does that even mean? Will it fail later during -[NSManagedObjectContext save:]...

Cross-model relationships in NSManagedObjectModel from merged models?

Is it possible to model relationships between entities that are defined in separate NSManagedObjectModels if the entities are always used within an NSManagedObjectModel that is created by merging the relevant models? For example, say model 1 defines an entity Foo with relationship (one-to-one) toBar and that model 2 defines an entity Ba...

Automatically generated predicate row templates for to-many key?

In my Core Data managed object model, I have an entity Foo with a to-many relationship (with a to-many inverse) to entity Baz named baz. Baz has a string property named "tag". When I use [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:@"baz.tag"] inEntityDescription:FooDescription] to create the row ...

Modifying NSDatePicker for automatically generated predicate row templates

How can I modify the NSDatePickerElementFlags for the NSDatePicker in row templates for NSDate properties returned by [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:]? I would like the NSDatePicker to show hrs:minutes as well as the date. Update I've added an answer below, gleaned from the cocoa-dev lis...

Error handling in Core Data

A few weeks ago I started using Core Data for the first time in a non-trivial application. One of the things that surprised and confused me was how error handling works. To give an example, one of the first things I tried was setting my data file as "locked" in Finder, to order to make sure I was properly handling the NSError object retu...

Fetching Core Data entities, but not sub-entities

Say I have entities organized in a hierarchy with Parent being the root entity and Child being a subclass of Parent. I'd like to setup an NSArrayController to fetch only entities of Parent, but not Child. If you set the Entity Name of the array controller in Interface Builder to Parent, it fetches all Parent and Child entities. I orig...

How do I customize an array controller's fetch request in Core Data?

In a previous question, I asked about how to filter out subentities from a Core Data fetch request on an array controller. The answer is to customize the fetch request used by the array controller. It seems I can easily do this in one of two ways. First, I could customize the fetch request in fetchWithRequest:merge:error: - (BOOL)fet...

What are the factors to decide between using Core Data versus rolling out a custom model?

There might be applications that are not suited for Core Data - image manipulation programs like Photoshop or Gimp for example. But for applications that are suited for Core Data, say Address Book or iCal, what is the criteria to choose Core Data over a custom model? ...

Can you Bind to the timeInterval attribute of an NSDatePicker?

I've got a Core Data application that has an Event class, which has a start date and a finish date. It's trivial to bind these to a pair of NSDatePicker widgets, but I wanted to make it work with the NSRangeDateMode available in Leopard. The NSDatePicker has a pair of methods that deal with timeInterval, but I don't seem to be able to ...

Sending fetch message to NSObjectController inside a modal loop.

I am using a modal sheet to edit a certain data entity. This sheet is run as application modal. When the sheet is launched, the object controller in the same nib as the sheet is set to the currently selected NSManagedObject. The code leading into the launching is as follows: [objectController setContent:object]; [NSApp beginSheet:[self...

Code review for many-to-many relationship UI implementation in CoreData

Below is the "work horse" piece of code that I've implemented in order to display a many-to-many relationship in CoreData. My UI is on a screen called "Expense". This expense can be associated with many transactions. (Also, transactions can be associated with several expenses). The UI contains the currently selected expense, and a table...

Manual Core Data schema migration without "document changed" warning?

The data model for my Core Data document-based app (10.5 only) is in a framework, so automatic schema upgrades using a Core Data mapping model don't appear to work. It appears that the Core Data machinery doesn't find the appropriate data models or mapping model when they are not in the app's main bundle. So, instead of using the automat...

What is the best way to model an Association Class in Core Data?

I have a relationship in a Core Data model that feels like it wants an association class. Specifically, I have a Person object, and a Location object. There is a many-to-many relation between these two classes, which has some properties, such as how many hours this person wishes to work at this location per week. How do I model this u...

Adding an image to NSPersistentDocument

I have subclassed NSPersistentDocument class. I want to add an image to the document. I have an Image Well. How do I set it to a .jpg file? ...

Syncing a Core Data Model With A Web Service

This problem has been kicking my butt for a few days now. I have a web service that serves XML that looks like this: <levels> <level>Level 1</level> <level>Level 2</level> <level>Consulting</level> <level>Office Support</level> <level>Learning</level> </levels> This data needs to go into an entity in my Core Data ...

Programmatically Update an attribute in Core Data

I've looked through all the class documentation for Core Data and I can't find away to programmatically update values in a core data entity. For example, I have a structure similar to this: id | title ============ 1 | Foo 2 | Bar 3 | FooFoo Say that I want to update Bar to BarBar, I can't find any way to do this in any ...

How to give title to NSPersistentDocument window

I have subclassed NSPersistentDocument. I have renamed the window too. But when I run the application I get the title of the application window as "Untitled". There is no -setTitle: method which I can use to change the title. Any ideas how can I go about doing this? ...

Data Store for a Mac/iPhone Hybrid App

I've been doing iPhone development for the last 5 months or so, and have been using Gus Mueller's FMDB for database interaction. My next project will have both a Mac and an iPhone application, and they will share data between them, although in the end, the iPhone will be mostly a viewer app, with some minor editing capabilities. My que...

When is an NSPersistentDocument's data store moved to final save location?

Following the advice in the Core Data Programming Guide's Core Data Performance page regarding storage of BLOBs, I've chosen to store binary data for my NSPersistenDocument-based app (Leopard-only, if that makes a difference) in an external file (separate from the document Core Data data store) and keeping an archived NDAlias reference t...