Objective-C programming

Discussion in 'Mac Programming' started by hrach, Mar 19, 2011.

  1. hrach, Mar 19, 2011
    Last edited by a moderator: Mar 19, 2011

    hrach macrumors newbie

    Joined:
    Mar 19, 2011
    #1
    Discussion about Objective-C programming language

    Hello guys,

    I have installed gnustep on my PC (OS: Windows).
    The GUI application is compiled successfully but when I executed the created application nothing is done (application is not shown and there is no any error).

    Below are coming my GNUmakefile and source file (MyApp.m)

    MyApp.m

    Code:
    #include <Foundation/Foundation.h>
    #include <AppKit/AppKit.h>
    
    @interface MyDelegate : NSObject
    - (void) printHello: (id)sender;
    - (void) applicationWillFinishLaunching: (NSNotification *)not;
    @end
    
    @implementation MyDelegate : NSObject 
    - (void) printHello: (id)sender
    {
      printf ("Hello!\n");
    }
    
    - (void) applicationWillFinishLaunching: (NSNotification *)not
    {
      NSMenu *menu;
      NSMenu *infoMenu;
      NSMenuItem *menuItem;
    
      menu = AUTORELEASE ([NSMenu new]);
    
      infoMenu = AUTORELEASE ([NSMenu new]);
    
      [infoMenu addItemWithTitle: @"Info Panel..." 
                action: @selector (orderFrontStandardInfoPanel:) 
                keyEquivalent: @""];
    
      [infoMenu addItemWithTitle: @"Help..." 
                action: @selector (orderFrontHelpPanel:)
                keyEquivalent: @"?"];
    
      menuItem = [menu addItemWithTitle: @"Info..." 
                       action: NULL 
                       keyEquivalent: @""];
    
      [menu setSubmenu: infoMenu  forItem: menuItem];
    
      [menu addItemWithTitle: @"Print Hello"  
            action: @selector (printHello:)  
            keyEquivalent: @""];
    
      [menu addItemWithTitle: @"Quit"  
            action: @selector (terminate:)  
            keyEquivalent: @"q"];
    
      [NSApp setMainMenu: menu];
    }
    @end
    
    int main (int argc, const char **argv)
    { 
      [NSApplication sharedApplication];
      [NSApp setDelegate: [MyDelegate new]];
    
      return NSApplicationMain (argc, argv);
    }
    GNUmakefile:

    Code:
    include $(GNUSTEP_MAKEFILES)/common.make
    
    APP_NAME = MyFirstApp
    MyFirstApp_OBJC_FILES = MyApp.m 
    
    # Uncomment the following if you have an icon
    #MyFirstApp_APPLICATION_ICON = MyApp.png
    #MyFirstApp_RESOURCE_FILES = MyApp.png
    
    include $(GNUSTEP_MAKEFILES)/application.make
    Execute application:
    openapp MyFirstApp.app


    Note:

    I have download and install Gorm. It works correctly and shows GUI application.


    Thanks in advance for any helps.
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    Please use CODE tags (the hash mark in the editor) around code and output.

    Are you following some sort of guide? If so, please link to it.

    What did you expect to happen?

    B
     
  3. sverrisson macrumors newbie

    Joined:
    Jan 14, 2011
    Location:
    Reykjavik
    #3
    You can use:

    Code:
    printf("Program working \n");
    to get comments on the console. This is the first step to see what is working.
     
  4. hrach, Mar 19, 2011
    Last edited: Mar 19, 2011

    hrach thread starter macrumors newbie

    Joined:
    Mar 19, 2011
    #4
    Thanks for your response.

    I expected to see window.

    When I have added printf in the main function there was no output on the console.
    After commenting all function in the source except printf in main function and updating make file the string has been printed on console.


    APP_NAME = MyFirstApp -> TOOL_NAME = MyFirstApp
    include $(GNUSTEP_MAKEFILES)/application.make -> include $(GNUSTEP_MAKEFILES)/tool.make


    I have no experience to develop GUI application using Objective-C.
    Could you please send me some example of GUI application (only simple window creation).
     
  5. hrach thread starter macrumors newbie

    Joined:
    Mar 19, 2011
    #5
    Also I have learnt about second desktop. Maybe the window opens in not current window and I will change it but I am not sure about it and I don't know how do it.

    I appreciate any advice.
    Thanks!
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Why do you expect to see a window? You have not created one or loaded a nib with one (at least anywhere I can see).
     
  7. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #7
    I will ask again.

    What resources are you using to follow along and learn Objective C in your environment? Please be specific.

    You may want to step back and learn the language first without the UI, build some console based apps using GNUStep's Foundation class http://wiki.gnustep.org/index.php/Foundation and then start worrying about the GUI.

    Note also that doing it on GNUStep/Windows will always be somewhat different than on a Mac or iOS.

    EDIT:
    That's exactly why I asked what the OP expected to happen. I too don't see any reason that code would be expected to create a window, but I really don't know how GNUstep handles things on Windows with the lack of a system wide menu bar, etc...

    B
     
  8. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    GWorkspace provides the system-wide menu bar ;)
     
  9. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #9
    Thanks! I knew it had to be handled somehow.

    @hrach, did you know that you needed to run GWorkspace?

    B
     
  10. hrach, Mar 20, 2011
    Last edited: Mar 20, 2011
  11. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11
  12. hrach thread starter macrumors newbie

    Joined:
    Mar 19, 2011
    #12
    I know C++.
    I want to learn Objective-C.
    I have install Leopard 10.5.2 on my PC successfully but I haven't manage to install and run Snow Leopard 10.6.3. The installation is OK but when I have run the OS it is hang.
    After I decided to use gnustep under Windows. And I want to sure that I can execute GUI application via gnustep.

    Note: I know Objective-C a little and I should learn much so to improve my skills.

    Thanks for your help and quick response. It is a GOOD forum with the GOOD members.
     
  13. hrach, Mar 20, 2011
    Last edited: Mar 20, 2011

    hrach thread starter macrumors newbie

    Joined:
    Mar 19, 2011
    #13
    To tell the truth I don't know what Gworkspace is. I will try to take a look at it.
    I have installed Gworkspace under Gnustep successfully.
     
  14. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #14
    I've had a quick look at those tutorials. You won't get a window (ignoring the system provided Info/About this app one) until you get onto the second tutorial "First Steps in GNUstep GUI Programming (2): NSWindow, NSButton".

    My suggestion is to keep working. Don't move on from one page until you understand it fully. This means you should understand each and every line of code: you should have known that there were no windows in the tutorial you linked to: don't move on until you understand why. That way by the time you complete the tutorial series you'll actually know something.
     
  15. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #15
    It would help to know your motivation to learn Objective-C. Do you plan on ultimately creating apps for the iOS App Store and Mac App Store or is this just a personal enrichment thing?

    There's nothing inherently wrong with the GNUStep tutorials you found, but IMHO you want to step back a bit and not worry about the GUI bits yet until you are on the platform you want to develop for. (Which I doubt is GNUStep on Windows).

    This may be a useful resource for you to read over. http://www.chachatelier.fr/programmation/objective-c.php

    B
     
  16. hrach thread starter macrumors newbie

    Joined:
    Mar 19, 2011
    #16
    Thanks. I'll continue to take a look at this link taking into account your advice.
     
  17. hrach thread starter macrumors newbie

    Joined:
    Mar 19, 2011
    #17
    Thank you for your help.
     
  18. hrach thread starter macrumors newbie

    Joined:
    Mar 19, 2011
    #18
    Thanks a lot!
    I have managed to create a simple window with your help.
    Now I come back and start to learn Objective-C at first as I know that I can also develop GUI application using Gnustep.

    Sincerely,
    Hrach
     

Share This Page