Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a user interface from an entity in Xcode 4?

I've been experimenting with core data for a couple of days and have spent the past couple of hours trying to work out how to create a UI from an entity in xcode 4. According to the books I've been reading you have to option drag the core data entity into a window in interface builder but when I do this in xcode 4, nothing happens. The apple documentation has been no help since it hasn't been updated for xcode 4. I'm sure it's something really obvious but I just can't figure it out.

like image 329
alexjohnj Avatar asked May 02 '11 09:05

alexjohnj


1 Answers

Your question is perfectly timed for me as I recently started learning Mac / Cocoa development and have come across the same problem.

After looking at the documentation, searching Google, trying out all Xcode menu options and playing around with every possible mouse & keyboard shortcut I could think of I have come to the conclusion that it is not possible to invoke the wizard to generate your interface from your entities in Xcode 4.

This answers your question but leaves you with the same issue I had - Where do you go now?

This is what I did to get my application to work (note that this is also explained in the videos linked to by Erik Aigner):

  1. Drag a new NSArrayController onto your NIB file. Open the attributes inspector and change the mode to "Entity" and change the Entity Name field to the name of your entity (E.G. Person).
  2. Create your interface as normal by dragging items onto your window.
  3. For each control you want to bind to your entity do the following: Select the control, open the bindings inspector and bind the value to the array controller. The controller Key field should be set to "selection" and the Model Key Path should be bound to the field of the entity you want to bind to (E.G. "name").

Obviously this only caters for a very basic scenario but should be enough to get you started (If you're reading the same book as me then be prepared for everything to break again in the next chapter when you try binding to related entities!).

There are still a few gaps in my knowledge as i've only been learning Core Data for 2 days (and Cocoa / Objective-C for less than a week) so if any of the information above is wrong then the Cocoa experts should let me know and I will update my post accordingly.

like image 67
Benjamin Gale Avatar answered Oct 11 '22 18:10

Benjamin Gale