• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: running an external app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: running an external app


  • Subject: Re: running an external app
  • From: "Gary L. Wade" <email@hidden>
  • Date: Tue, 27 May 2008 12:47:37 -0700
  • Organization: DesiSoft Systems

When starting out, it can be difficult getting used to the different style of function declarations and calls used in Objective-C, but as so many others have said, that's a basic requirement when learning a framework like Cocoa.

Anyone familiar with some C++-based object-oriented UI frameworks can attest to the fact that the documentation for MacApp, THINK Class Library, PowerPlant, wxWidgets, MFC, etc., do not explain the basics of how to make C++ function calls.

One of the things that helped me in the transition from C++ to Objective-C was to do a mental mapping of the different syntaxes. For example, if NSWorkspace were a C++ class, it might be declared like this (only the relevant details needed are included) with one of the more parameterized methods (launchApplication:showIcon:autolaunch) illustrated (also included is sharedWorkspace):

class NSWorkspace: public NSObject
{
public:
    static NSWorkspace*
    SharedWorkspace (void);

    // This is named slightly differently in order to illustrate
    // the mental mapping required when reading it.
    virtual bool
    LaunchApplicationWithOptionsToShowIconAndAutolaunch (
        NSString* appName,
        bool      optionToShowIcon,
        bool      optionToAutolaunch);
};

Note that I purposely named the parameters differently in order to illustrate what was part of the method name and what was not, and NSWorkspace's declaration for launchApplication:showIcon:autolaunch could similarly be:

-(BOOL)launchApplication:(NSString *)appName
 showIcon:(BOOL)optionToShowIcon
 autolaunch:(BOOL)optionToAutolaunch;

Anyone familiar with C++ would know that to call this method, they would need an NSWorkspace object, and the presence of the class-static method SharedWorkspace is a strong implication that it can be used.

bool didLaunch =
(NSWorkspace::SharedWorkspace ())->
    LaunchApplicationWithOptionsToShowIconAndAutolaunch (
        anApplicationNameInNSStringObjectFormat,
        true,
        false);

In Objective-C, you can map that C++ rendition into:

BOOL didLaunch =
[[NSWorkspace sharedWorkspace]
    launchApplication:anApplicationNameInNSStringObjectFormat,
    showIcon:YES,
    autolaunch:NO];

When just starting out, try line-breaking after each parameter in your own declarations and function calls to see if that helps you to conceptualize the differences between Objective-C and C++; doing so also helps if you don't have a 30" monitor to avoid horizontal scrolling when trying to get an eyeful of your code.

If you're more familiar with Java, C#, or other object-oriented languages, try to find a mental map that is familiar to you and, if necessary, recite/rewrite your code in a way similar to above as long as it takes until you don't need to do it anymore.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: running an external app (From: Peter Duniho <email@hidden>)
 >Re: running an external app (From: "Hamish Allan" <email@hidden>)

  • Prev by Date: Dealing with NSError outside of the Responder chain
  • Next by Date: Re: running an external app
  • Previous by thread: Re: running an external app
  • Next by thread: Re: running an external app
  • Index(es):
    • Date
    • Thread