Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Weltschmerz

macrumors newbie
Original poster
Oct 14, 2004
4
0
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

Moderator emeritus
Jun 25, 2002
16,120
2,397
Lard
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

macrumors 6502
Jun 14, 2002
314
312
Mountain View, California
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

macrumors newbie
Original poster
Oct 14, 2004
4
0
Santiago said:
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.

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

Moderator emeritus
Oct 8, 2002
9,992
31
The Bamboo Forest
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

macrumors newbie
Original poster
Oct 14, 2004
4
0
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

macrumors 6502
Jun 14, 2002
314
312
Mountain View, California
Weltschmerz said:
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

macrumors 6502
Jun 21, 2004
258
0
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

macrumors newbie
Original poster
Oct 14, 2004
4
0
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

macrumors 65816
Apr 19, 2004
1,144
0
Secret Moon base
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors newbie
Aug 4, 2006
1
0
A little lost

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?
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
Code:
#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

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
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

Suspended
Nov 25, 2005
17,980
5,566
stonz2 said:
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.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
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

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
Catfish_Man said:
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

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
Catfish_Man said:
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

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
kingjr3 said:
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.