7

I am trying to build an document-based application for beer reviewing that allows you to enter your notes. I have built the model in Core Data and the view in Interface Builder. Following some Xcode 3-based tutorials, I am told to connect the new NSArrayController to the managedObjectContext of File's Owner. If I try and do this in Xcode 4, a circled exclamation point comes up next to "Model Key Path" in the inspector for the NSArrayController.

I can actually load the .xib file in Interface Builder in Xcode 3, make that connection, and then build it in Xcode 4 and it runs, but every field raises a validation error.

The model has an entity named Scoresheet, which has a property named date, which is an NSDate. But if I link it to the value of an NSDatePicker and try to save it to disk, it says I have "multiple validation errors." How can that be? They are both NSDates, right? Actually, I have the same problem with bindings to everything; none of my UI objects will work with my model.

The only thing I can figure is that there is something going wrong in the connection between the File's Owner and the NSArrayController.

I haven't written any code at this point, because I'm of the understanding I shouldn't have to just to link UI fields and core data. Is it different because I am using a document-based application? (I can't get it to work in a single window app, either.)

An answer of "don't use Core Data" isn't going to be productive; I know I can just fall back on a regular data object. I would like to figure this out in the context of Core Data if possible.

TIA!

(Update: this question seems to be vexing a lot of people. I have consulted the Zarra book on Core Data, the Hillegas book on Cocoa Programming, and two O'Reilly books. They all seem to be based on Xcode 3.)

sj660
  • 81
  • 1
  • 5
  • What happens if you add a managed object context to the xib file? On a test project I was able to bind an array controller to the managed object context, but I got an error when I ran the project saying I couldn't create an NSArray of class NSManagedObjectContext. But it might work for you since you have a working data model and I had a dummy data model. – Swift Dev Journal Jun 12 '11 at 05:51
  • The File's Owner in the xib should be your document's class, as ImHuntingWabbits stated in his answer. What class have you set for it? And which NSArrayController property are you trying to connect it to? – Huperniketes Jun 16 '11 at 07:12

2 Answers2

4

NSPersistentDocument has it's own managed object context, and you should bind the NSArrayController in your document's xib file to that managed object context.

For example, if your document class is called MyDocument, then Xcode will automatically generate a MyDocument.h / .m / .xib for you. In the .xib, the File's Owner is an instance of your MyDocument class, and you can bind the NSArrayController to this, with the binding File's Owner -> managedObjectContext.

ImHuntingWabbits
  • 3,827
  • 20
  • 27
  • If I understand sj660 correctly he has done exactly what you suggest... and he's still getting the exclamation point and the errors. I also get the exclamation point, but I get a different set of errors. I created a fresh project in Xcode 4 and did nothing except create a single entity and an array controller. I tried to bind the array controller to the File's Owner -> managedObjectContext and run the program and I get: 2011-07-06 19:40:35.616 FlashCard2[92229:903] -[FlashCardDocument persistentStoreCoordinator]: unrecognized selector sent to instance 0x10013a610 – Jason Jul 06 '11 at 23:40
  • I have Xcode 4.0.0 build 4A303a, 4.0.2 build 4A2002a is out and I'm downloading it now. Maybe it will fix the problem. – Jason Jul 06 '11 at 23:45
  • It sounds like you have a different issue, but it's a little hard to tell without the complete stack trace from that crash. – ImHuntingWabbits Jul 11 '11 at 16:46
0

I am running into the same problem (the CarLot example in Chapter 11 of Hillegass, right?)

The following blog entry is from a developer who wrote and maintains an extension for use with NSManagedObjects and considers this a bug in XCode 4 and has filed a report in rdar : http://danieltull.co.uk/blog/2011/04/20/xcode-4-and-creating-nsmanagedobject-subclasses/

I have a machine with XCode 3 on it, I will eventually give up beating on this in 4, create the project in XCode 3 and import it into XCode 4.

Edited to add: Adding the element in XCode 3 and linking the outlet, and then importing the project into XCode 4 works fine, it does seem that this is a bug in XCode 4. I do not get validation problems from XCode 4 doing this.

Todd Masco
  • 218
  • 3
  • 11