Trying to make a cocoa application, very simple

Discussion in 'Mac Programming' started by JDoggG4, Dec 22, 2007.

  1. JDoggG4 macrumors newbie

    Joined:
    Aug 25, 2007
    #1
    Hey guys I'm trying to make a cocoa application that has a GUI that shows a drop down menu and a button called "Launch", the user chooses a game from the list and clicks "Launch", once they do that the application launches ([[NSWorkspace sharedWorkspace] launchApplication;, or something like that) I just started cocoa programming and really hope you can help me with this problem I'm having.


    main.m
    Code:
    //
    //  main.m
    //  XG-Emulator
    //
    //  Created by JDogg on 22/12/07.
    //  Copyright __MyCompanyName__ 2007. All rights reserved.
    //
    
    #import <Cocoa/Cocoa.h>
    
    int main(int argc, char *argv[])
    {
    	NSString *chosenGame = [dropDown selectedItem];
    [[NSWorkspace sharedWorkspace] launchApplication:chosenGame];
    }
    
    untitled.h
    Code:
    #import <Cocoa/Cocoa.h>
    @interface dropDown : NSObject
    {
    	NSString *chosenGame = [dropDown selectedItem];
    	[[NSWorkspace sharedWorkspace] launchApplication:chosenGame];
    	
    }
    @end
    I get the error "dropDown undeclared (first use in this function)
    Download the XCODE (3.0) Project:http://deathlyinvasionclan.com/jmacsoft/files/XG-Emulator.zip
     
  2. mduser63 macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #2
    You're doing it completely and totally wrong. Get Programming in Objective-C by Stephen Kochan and read it.

    (I'm not trying to be rude, but really you're so far off that by the looks of it one would have to give you a complete introduction to Object Oriented programming and the Objective-C language. That's too much to ask in a forum thread. Getting a book on the subject will be a much better way to go.)
     
  3. JDoggG4 thread starter macrumors newbie

    Joined:
    Aug 25, 2007
    #3
    I'm currently reading COCOA PROGRAMMING FOR MAC OS X SECOND EDITION By Aaron Hillegass. And you are right, I should read more, but all I want to know is how I can get the program to work
     
  4. mduser63 macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #4
    Well what I'm trying to say is that it's not a short answer or a matter of tweaking what you're already got. You need to start over because what you've got is not even the beginnings of a working application. The main() function you've got should have remained unchanged from the template. What you have in there shouldn't be in there at all. The second file is a header. Headers are supposed to contain declarations only, no definitions. You've got actual code in there. Really it's difficult to explain. It's like if someone posted asking for help getting their car to start and asking if you could you just explain the minor mistake they'd made. You come in expecting to tell them to make sure they hold down the brake before shifting into drive, but instead they've posted a picture of a dead elephant with a wheel glued to its head and an exhaust pipe for a tail and you just really can't even begin to explain the problem...because they so obviously don't know where to start.

    The book you've got is an excellent one, but I would suggest going through the book I mentioned earlier. Before you can effectively learn Cocoa (the APIs) you need to know Objective-C (the language) and it's pretty clear that you don't yet have a good grasp of the language yet.

    Again, I'm really trying to help, but you need a more than a little help, you've got a lot to learn first. Programming is not simple or easy, but it is very much worth learning, so keep at it.
     
  5. JDoggG4 thread starter macrumors newbie

    Joined:
    Aug 25, 2007
    #5
    Thank you very much for your pointers and advice. I agree it would be easier to learn objective C before getting into Cocoa, so I am going to buy the book you recommended and hopefully I learn something from it. I have no programming background besides HTML, applescript and a little tiny bit of Java
     
  6. mduser63 macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #6
    That's a good way to go and you'll be glad you did. For what it's worth, I've read a lot of technical books (I have a degree in electrical engineering and do that for a living) and Kochan's book is one of the best I've ever read. If you go through it and do all the exercises you'll come out the other end quite comfortable with ObjC and Hillegass's book will be much easier to get through and understand. Don't hesitate to ask questions here if there's something you don't understand, but do make sure you've done your homework first.
     
  7. tjwett macrumors 68000

    tjwett

    Joined:
    May 6, 2002
    Location:
    Brooklyn, NYC
    #7
    i'd like to just say that is the funniest damn thing i've ever read on these forums, and i've been around a while. i think i just LOL'd in my pants.
     
  8. Nutter macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #8
    Yes, I agree. That was a rather excellent analogy.
     

Share This Page