Steps to convert a new xcode cocoa project using 1 controller per nib - xcode

I want to start off my new xcode project using 1 nib per controller. By default it seems xcode creates:
1. delegate .h/.m
2. MainMenu.xib
And looking at the targets for the project, I see that the 'main nib file base name' is set to MainMenu, the principal class is NSApplication.
Since cocoa is MVC based, how are things MVC based on the default template?
How can I wire things together with a 'MainWindowController' instead of this default setup? If someone can explain the steps to me that would be much appreciated.

You don't want to subvert or change the default setup, just to understand it and work within it. MVC is a description of responsibility rather than some hard requirement about naming.
The delegate .h/.m is the app delegate by name, but its responsibility is to be the app controller. It gets everything setup when the app starts and deals with application level events. It shouldn't do anything that isn't related to application level management.
The MainMenu.xib is just a container / archive of the first Views and Controllers that are to be created when the application opens.
There is no Model in the template really as all it does is display the main window with a static string on it...
Your goal of using 1 nib per controller is fine, but you should be a little flexible with the naming at first. Because the MainMenu.xib contains the main window it should also contain your MainWindowController. This is perfect from an MVC point of view because you are separating the responsibility.
Then, your future Controllers and Views (in their XIBs) can have matching names to keep everything clear. And you can created your Model separately.

Related

How to change Xcode generated files to Swift from Objective-C

I am new to Xcode and am not sure what I am doing. However a projected I am working on started with Objective-C, and upon realizing aspects of the language, I'd like to change to Swift. Whenever I make a view controller on storyboard, it makes it in Objective-C. How can I change the settings so it makes the auto-generated files in Swift instead?
Should be easy, right? I do not want to restart the project.
Thanks.
Whenever I make a view controller on storyboard, it makes it in Objective-C
A view controller on the storyboard has no language, and making a view controller in the storyboard does not auto-generate any files, so the question as it stands makes no sense.
What does have a language are the view controller subclass files you create for the project. The language of those is up to you at the moment of creation. Note the language pop-up in the File > New > File dialog:

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.

How can I change the default code generated when creating a new file in Xcode5?

I must be wording this funny because I can't even get close to a fruitful search.
When I create a new file through the graphical interface (right-click -> new file -> Objective-c class) I want my personal pragma marks to be stubbed out.
How can I specify a template for this in Xcode5?
I apologize if this is obvious or well documented already.
EDIT 11/18
To be more specific, I am not talking about project templates (Master-Detail, Tabbed Application, etc) but rather file templates. An example would be how new (Xcode generated) UIViewController subclasses come with some of the view lifecycle delegate methods like viewDidLoad and such. I would like control over that boilerplate/stubs are created on a per-file/subclasss basis.

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.

MVC Structure?

I am having some difficulty getting my head around the MVC structure.
What I am still struggling with is, when creating the Control to accompany the supporting code, does one need to include the Object within IB?
Think of IB as a freeze-dried version of an object. It is the object itself in visual form. It's stored in the xib file and pulled out when referenced.
You don't NEED to use IB. You can create an object and add it to a view without ever opening the visual tool (some people prefer to work that way).
Storyboarding carries this to an even greater level where you can create the interaction between views in the form of segues.

Resources