GUI Programming without XCode

I'm currently learning Objective-C. I want to use it to start writing Cocoa applications, but most Cocoa resources I've found so far teach you how to use Xcode to create Cocoa apps. I just want to write straight Objective-C first, then learn to use the IDE later (call me old-school). Where should I look?

If you really want to write GUI code without Interface Builder, you're going to have to create the .Nib files on your own. I suppose that you could copy-and-paste from current files but it would be so difficult that it wouldn't be worth it.

Xcode is the IDE. Interface Builder is the tool for creating nib files, which are basically serialized Cocoa objects that the OS loads for your program. Unlike many other GUI tools, Interface Builder does not output code that creates the objects you want.

Xcode is very useful even if you are not making GUI apps. Only a complete masochist would prefer to use a text editor and manual invocation of the command-line compiling and linking tools.

Developing Cocoa apps without using Interface Builder is a really bad idea. It's kind of like learning to drive without turning on the motor, but getting out and pushing the car a few feet, then getting back in to turn the wheel a bit, getting back out and pushing some more, and so on.

Xcode is very useful even if you are not making GUI apps. Only a complete masochist would prefer to use a text editor and manual invocation of the command-line compiling and linking tools.

Click to expand...

I have been known to exhibit this type of masochism in the past.

Santiago said:

Developing Cocoa apps without using Interface Builder is a really bad idea. It's kind of like learning to drive without turning on the motor, but getting out and pushing the car a few feet, then getting back in to turn the wheel a bit, getting back out and pushing some more, and so on.

Click to expand...

I appreciate the advice (and the car simile). This certainly explains why my search has been so unsuccessful. It just seems strange to me that there is no first-principles approach to the programming. It feels like I want to learn HTML, but I'm being told I have to use FrontPage.

You can write programs using Obj-C and not using any GUI at all if you wish. Obj-C and Cocoa are separate things which when combined can be used for good (or evil I guess...). Learning Obj-C and then Cocoa would be like learning C++ and then using the VC++ to start making Windows apps. Just get a good book on Obj-C.

I understand that Obj-C and Cocoa are different things, and I made sure my first book was only about Obj-C. I'm most of the way through it, and I do want to get good at programming Obj-C by itself first. I just wasn't aware that as soon as I wanted to write a program with GUI elements, I had to make the move to XCode.

It just seems strange to me that there is no first-principles approach to the programming.

Click to expand...

In Cocoa philosophy, user interface is not a programming task. It is a design task, and thus better carried out by a design tool. You don't generally make the images your application uses via code, but rather via an image-design tool, such as Photoshop. Likewise, the user interface is created via Interface Builder. The actual act of programming is then relegated to the core functionality of actually doing something interesting. With the new bindings mechanism, much of the trivial data manipulation that was formerly viewed as a programming task is now merely a matter of specifying how the data should flow in Interface Builder. It's all based upon a conceptual shift to using different tools for different purposes.

Also take note of the fact that it's never really been different since the creation of NeXTStep in '88. XCode is based on Project Builder which was the IDE for NeXTStep. It's been a complete package from the beginning - Objective-C and the API (which is now called cocoa) and the IDE, just like, for example, Borland Delphi.

Coding in Objective-C without cocoa and Xcode is like programming Object Pascal without VCL and Delphi. If you're familiar with Delphi you can imagine why it isn't practically useful.

If you're really such a masochist, you could even use a modern GCC on something like linux, because I believe that supports Obj-C too. No need for Mac OS X in that case.

Well, if a conceptual shift is required, I shall attempt to shift my concept.

And it does make sense; I work with things like Oracle Forms every day at work, and it's not like I create them with code. I think the problem is that I was seeing Cocoa more as a language than an environment.

AFAIK, there's nothing magic about the .nib file, it's just a bunch of Objective C objects (specifically GUI controls) that get de-serialized at run time. So I don't see why one could not simply instatiate said objects in normal objective C code. I haven't investigated this, but I would be very surprised if you can not simply use Cocoa objects like any other object. I don't see why one would need Interface Builder. Also I understand the desire to learn it manually first, that would be my approach.

Whilst you all seem to have done a great job of talking up XCode/Interface Builder (which are great tool when XCode doesn't crash) it is possible to create a Mac OSX GUI app without using either. Nib files are just a nice simple way of enabling the visual design of the GUI. There is nothing to stop you create an NSWindow object in your code populating it with NSViews and NSControls and then showing it on screen. So that gets rid of Interface Builder! You don't really need XCode either. Write your code in TextEdit and just run the command line compiler to compile to object code. Move the executable into a hand created .app wraper structure and run.

So, I'm pretty new to this whole Xcode/Cocoa/Interface Builder/Obj-C thing, but I'm getting the hang of it quickly (I used C++ in college) and I'm also wanting to at least learn a little about the underlying code for the GUI. I've been looking around in Xcode though and I can't seem to find anything that looks like the actual code for the GUI. Which files would I be looking for that would contain this?

So, I'm pretty new to this whole Xcode/Cocoa/Interface Builder/Obj-C thing, but I'm getting the hang of it quickly (I used C++ in college) and I'm also wanting to at least learn a little about the underlying code for the GUI. I've been looking around in Xcode though and I can't seem to find anything that looks like the actual code for the GUI. Which files would I be looking for that would contain this?

Click to expand...

If you really want to do things by hand, Carbon is the way to go. It is much more low level. Go to developer.apple.com, look at the Carbon documentation. Or check out the "Appearancesample" program, which demonstrates about every bit of user interface there is.

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.