PDA

View Full Version : GUI Programming without XCode




Weltschmerz
Oct 14, 2004, 01:56 PM
Hi all,

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?

Thanks in advance,
Weltschmerz



bousozoku
Oct 14, 2004, 02:17 PM
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.

I'd really suggest using the Xcode IDE.

Santiago
Oct 14, 2004, 03:02 PM
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.

Weltschmerz
Oct 14, 2004, 05:59 PM
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.
I have been known to exhibit this type of masochism in the past.

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

Cheers,
WS

SilentPanda
Oct 14, 2004, 06:06 PM
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.

Weltschmerz
Oct 14, 2004, 06:13 PM
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.

Cheers,
WS

Santiago
Oct 14, 2004, 06:42 PM
It just seems strange to me that there is no first-principles approach to the programming.

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.

MacNeXT
Oct 14, 2004, 07:11 PM
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.

Anyway, have fun!

Weltschmerz
Oct 14, 2004, 08:43 PM
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.

Thanks to all who replied.

broken_keyboard
Oct 14, 2004, 09:40 PM
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.

robbieduncan
Oct 15, 2004, 04:21 AM
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.

It's much easier with XCode though.

stonz2
Aug 4, 2006, 08:07 AM
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?

caveman_uk
Aug 4, 2006, 09:03 AM
which are great tool when XCode doesn't crash
I must be very lucky because it hardly ever crashes for me. :D

hsvmoon
Aug 4, 2006, 09:06 AM
Quick GUI development I find easier in JAVA and the results are portable.

gekko513
Aug 4, 2006, 09:43 AM
#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
int style = NSClosableWindowMask | NSResizableWindowMask |
NSTexturedBackgroundWindowMask | NSTitledWindowMask | NSMiniaturizableWindowMask;
NSWindow *win = [[NSWindow alloc] initWithContentRect:NSMakeRect(50, 50, 600, 400)
styleMask:style
backing:NSBackingStoreBuffered
defer:NO];
[win makeKeyAndOrderFront:win];
[NSApp run];

[pool release];
}

Put this in a file, for instance "test.m", compile it:
gcc test.m -o test -lobjc -Wno-import -framework Cocoa
Run it:
./test

And voila, you have a window on the screen. No menu bar, no dock icon and no normal way to quit, though, but it's a starting point.

I'd still suggest just starting out with Xcode and Interface Builder for the reasons others have given here.

whooleytoo
Aug 4, 2006, 10:11 AM
While I develop almost exclusively via Xcode at the moment, I'm probably going to move my build process to the command line soon - it's simpler if you need to automate a complex build.

Then, Xcode is little more than a text editor (which could be replaced by any other with syntax colouring) and a graphic debugger.

gnasher729
Aug 4, 2006, 02:31 PM
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?

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.

caveman_uk
Aug 4, 2006, 02:56 PM
If you really want to do things by hand, Carbon is the way to go. It is much more low level.
If you want to make your life difficult then use Carbon...

Catfish_Man
Aug 4, 2006, 03:10 PM
I'm astonished there's so many people here that don't know that you can create GUIs programmatically in Cocoa. Complex apps are impossible without that capability.

HiRez
Aug 4, 2006, 05:20 PM
I'm astonished there's so many people here that don't know that you can create GUIs programmatically in Cocoa. Complex apps are impossible without that capability.To augment a design, sure, but to do the entire interface that way? No thanks! I did that for a few years when I was doing Java and it would be very painful to go back to that way.

jeremy.king
Aug 4, 2006, 06:30 PM
I'm astonished there's so many people here that don't know that you can create GUIs programmatically in Cocoa. Complex apps are impossible without that capability.


Um...this thread is nearly two years old...perhaps things have changed since then.

Catfish_Man
Aug 5, 2006, 03:42 AM
Um...this thread is nearly two years old...perhaps things have changed since then.

Well, I'd certainly hope more people know it's possible* than did two years ago. The API certainly allowed it two years ago... or ten.


*unpleasant though, I agree.

gekko513
Aug 5, 2006, 04:23 AM
Um...this thread is nearly two years old...perhaps things have changed since then.
I didn't notice that. :o