GUI Programming without XCode

Discussion in 'Mac Programming' started by Weltschmerz, Oct 14, 2004.

  1. macrumors newbie

    Joined:
    Oct 14, 2004
    #1
    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
     
  2. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #2
    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.
     
  3. macrumors regular

    Joined:
    Jun 14, 2002
    Location:
    Mountain View, California
    #3
    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.
     
  4. thread starter macrumors newbie

    Joined:
    Oct 14, 2004
    #4
    I have been known to exhibit this type of masochism in the past.

    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
     
  5. Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #5
    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.
     
  6. thread starter macrumors newbie

    Joined:
    Oct 14, 2004
    #6
    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
     
  7. macrumors regular

    Joined:
    Jun 14, 2002
    Location:
    Mountain View, California
    #7
    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.
     
  8. macrumors 6502

    Joined:
    Jun 21, 2004
    #8
    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!
     
  9. thread starter macrumors newbie

    Joined:
    Oct 14, 2004
    #9
    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.
     
  10. macrumors 65816

    broken_keyboard

    Joined:
    Apr 19, 2004
    Location:
    Secret Moon base
    #10
    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.
     
  11. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11
    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.
     
  12. macrumors newbie

    Joined:
    Aug 4, 2006
    #12
    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?
     
  13. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #13
    I must be very lucky because it hardly ever crashes for me. :D
     
  14. macrumors newbie

    Joined:
    Jul 31, 2006
    Location:
    Huntsville Al
    #14
    JAVA anyone?

    Quick GUI development I find easier in JAVA and the results are portable.
     
  15. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #15
    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.
     
  16. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #16
    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.
     
  17. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #17
    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.
     
  18. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #18
    If you want to make your life difficult then use Carbon...
     
  19. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #19
    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.
     
  20. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #20
    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.
     
  21. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #21

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

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #22
    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.
     
  23. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #23
    I didn't notice that. :eek:
     

Share This Page