• 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: Wayne Packard <email@hidden>
  • Date: Mon, 26 May 2008 21:14:43 -0700

Objective-C methods are always invoked the same way. Once you learn that way (by, gods forbid, reading an introduction to the language) then the method declaration (including the name, argument types and return type) is all you need to tell you how to call it. You do not need a redundant line in the docs for every method showing you how to use it. It's an Objective-C method; you should already know how to call it.

The OP created an instance of something of type "bool" then tried to call a method on it. If he was familiar with the language enough to be writing an app beyond "Hello World", he'd know things like bool is not an Obj-C type, return values for Obj-C methods are specified in parens before the method name in declarations, the square bracket syntax specifies the object you want to message followed by the message and optional arguments, the variable to receive the return value doesn't go inside those brackets, etc. That's all basic stuff. It applies to every call. Learn it one day, use it everyday.

What is the point of this seemingly never-ending discussion about how horrible the Objective-C and Cocoa documentation supposedly is? I created a mail rule to nuke those posts days ago, but now the same freakin' topic is being rehashed in other threads. "Cocoa-Dev - all newbie complaints, all the time!"

Once you have laid the groundwork of a basic understanding of the language, the Cocoa docs are fine. The fact that you cannot open the documentation for an arbitrary method in an arbitrary class and infer from it everything you will ever need to know to write the next version of MS Office is not a shortcoming in the documentation.

Cluttering the docs by repeating every bit of basic information over and over in any place you may possibly need it would be unworkable and quite UNDESIRABLE for anyone who already knows the language. And where would it stop? What if the reader doesn't know what a variable is? What if he's confused by the English language use of definite and indefinite articles? Do we throw in a short English grammar primer at the bottom of each page?

On a personal note, if figuring out how to turn a method declaration into a valid method call perplexed you for a year, maybe programming isn't for you.

wp




On May 26, 2008, at 8:29 PM, Johnny Lundy wrote:

True the OP needs to learn Objective-C. But let me just throw in here one of my infamous objections to the documentation, namely the Class Reference sections.

Here is the Class Reference documentation on NSWorkspace's launchApplication: method:


launchApplication:
Launches the specified application.

- (BOOL)launchApplication:(NSString *)appName

Parameters

appName
The name of the application to open.

Return Value
YES if the application was successfully launched or was already running; otherwise, NO.



Now the line
- (BOOL)launchApplication:(NSString *)appName

May be technically the declaration of the method, but is that really useful to anybody? After all, you do not declare this method in your code; you just invoke it. I can't tell you how many times I have been led astray by this terminology - took me at least a year to figure out that the way it is written has nothing to do with how you use it.


The way you would use it is something like

(BOOL) loadedIB = [[NSWorkspace sharedWorkSpace] launchApplication: @"Interface Builder"];

Which bears no resemblance to the line that is written in the documentation.

This OP is NEVER going to figure that out from the line in the documentation. Even the "discussion" goes on and on about .app extensions and what notifications the method sends, but never mentions how to invoke the thing.

This is why they need to put at least one line in every one of these method documentations to show how it is invoked.

I expect replies to the effect of "it would bloat the documentation", etc., but the fact is, that single example could clarify 1) That you have to message the sharedWorkspace instance, and 2) That you don't actually code "- (BOOL)launchApplication: (NSString *)appName".

With the huge influx of new Cocoa programmers we are about to see, Apple might give some thought to whipping up some example lines to put in these "Class References." Every other reference manual I have ever seen gives the metalanguage and also an example line.

That this OP's basically trying to copy the Reference text in his code shows me that this confusion is very common.

<_< I still have the problem of invalid receiver type bool. The
program compiled but pressing the button did nothing. Please note that
the color of the word "bool" is not pink like it should be.


bool runApp;

whereas:

float firstNumber;

is pink.

I'm also having another problem.... how do I append a single digit to
an int like a calculator does? Again, I checked the documentation and
online but no luck. Am I missing some secret to searching the
documentation? Thanks!

_______________________________________________

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

_______________________________________________

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: Johnny Lundy <email@hidden>)

  • Prev by Date: Re: running an external app
  • Next by Date: Re: File's Owner
  • Previous by thread: Re: running an external app
  • Next by thread: Re: running an external app
  • Index(es):
    • Date
    • Thread