How to use "Custom Objects" in IB in XCode 4 - xcode

This is in Xcode 4 and it leads me to believe that I can create, and reuse, custom objects. However, I can not find any method of doing so.
How do you use this? Does anyone know?

Short answer: you currently can't use the Custom Objects section to create custom objects.
The Custom Objects section contains third-party Interface Builder elements. Older versions of Xcode and Interface Builder supported the creation of custom user interface elements. BWToolkit contains examples of custom elements. If you open an old Xcode project in Xcode 4 that contains custom elements, those elements appear in the Custom Objects section. Xcode 4 does not currently allow you to edit xib files that contain custom user interface elements, reducing the usefulness of the Custom Objects section.
If you would like to be able to create custom user interface elements in Xcode 4, file a bug report with Apple.

Related

Add a second UIViewController within a single-view application

I have a single-view application open. I need to have two storyboard views (UIViewControllers), because one is a Table View, but when one of the Table View elements is selected it brings up another screen with a normal UIViewController. Is there any way of creating a second storyboard view (UIViewController)?
Of course! Those templates Xcode provides are in no way "set-in-stone". When Xcode created your Single-View Template, it just gave you a base for creating something more. You can create additional classes, view controllers, views, and resources (other than what Xcode starts you off with in a few ways).
To add another View Controller to your Storyboard, just drag and drop one from the Object Library:
It seems like you do not have a basic understanding of using or developing with Xcode. I would recommend reading over all of Apple's documentation on Xcode before going any further. The Building A User Interface section may be of particular interest to you.

External Object placeholders in Xcode's Interface Builder are missing

If I remember correctly, it use to be possible to add external object placeholders to a NIB in interface builder. This was used to add reference to existing instances of objects that the NIB doesn't create but need to be referenced by other objects in Interface Builder. Similar to "File's owner" and Application objects.
I also found some mention in older SO questions of this technique, for example here
I am using Xcode 5.0.1 on Mavericks and there is no trace of these "External Objects" in interface builder. It seems that it is not possible to add anything to the placeholders anymore. I went through Xcode's release notes since Xcode 4.0 and there is no mention of this being removed (although there are few mentions of dragging placeholder, whatever that means).
So, any idea if this was intentionally removed? A bug? Is there any workaround or replacement for this feature?
Open the project which has already used external object, you will find 'external object' in the interface builder. So I guess the external object may be deprecated and not appear by default.
For an alternative way, you can use 'object' instead.

Cocoa how to handle multiple views?

I'm have done some development on iOS using Storyboards. Now I'm building on app for Mac OS X and it seems that an equivalent for Storyboards does not exists.
For instance, I'm need to build some kind of wizard, which contains four different windows or views (step 1 to 4).
Currently I've created one Window xib (the standard MainMenu.xib), containing a window with the first view, and three other custom views. Using this approach, I can create outlets and actions, making me able to change the contentView of my window, e.g. when clicking an button. This seems as a fair solution, and my views are all grouped cleanly inside a single xib. But this also cause that the logic for all the view should be handled by the same File's Owner, right? For instance saving the settings on each step and controlling the interaction between the different views.
How is the preferred way to handle a situation like this? Should I instead create four different windows, and maybe in four different xib-files? If you know an sample project somewhere from the internet showing how to handle multiple windows, please give me a hint.
You can make use of the NSViewController class for this purpose. Each view controller will be responsible of loading a xib associated with it and all logic associated with the views can go inside the controllers (Same as in iOS). The MainMenu.xib can now load appropriate views after initialising the required view controllers.
Here is a sample app for your reference.
https://developer.apple.com/library/mac/samplecode/ViewController/Introduction/Intro.html
In xcode, go to File->New->New File
Add an objective C class and set it to subclass of "NSViewController".
This will itself create yourController.h, yourController.m and yourController.xib.
Now you can keep your view and its controller class seperate.

How to add a custom object to Xcode?

I want to create an object and use it on my project. I able to do it, but under the objects panel of xib file there is a pop up list that shows these values:
Cocoa touch [Controls, Data Views, and ...]
Custom objects
The Custom objects list is empty! Is any way to add my objects to this list? What is this list exactly?
This list is indeed meant to save custom object templates. You could create those custom objects and then pull them into the list for later reuse.
However, it doesn't seem to work in the current stable version (4.5.2) of Xcode.
You should check if it works in the latest developer preview. If it doesn't you should probably file a bug.

What do you bind NSArrayController's Managed Object Context to in Xcode 4?

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.)
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.
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.

Resources