Re: running an external app
Re: running an external app
- Subject: Re: running an external app
- From: Adam Leonard <email@hidden>
- Date: Mon, 26 May 2008 21:28:47 -0700
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.
Ok, well first of all, calling methods is one of the most basic
concept in any language. I fully understand that it looks quite
different in objective c than most other c based languages, but I
don't see how that makes it difficult. That is why the basic guides
and such that everyone pointed out to the OP to read are so important.
They very clearly explain how methods are invoked and I just can't
understand how you could have used the language for a year without
figuring that out.
Now that line in the documentation is there for a few reasons.
First, that is exactly what you would see in the header file, which is
all the documentation you get with a whole lot of third party code.
Second, although it looks nothing like how the method is invoked, if
you understand how ANY method is invoked it will probably tell you
everything you need to know, without even reading the rest of the
documentation. It tells you the named parameters, which you can
usually guess as to what they refer to, the types they take, and the
value returned. All of this is on one short line. I usually find it
much faster to use the method signature to figure out how to call the
method. Again, all you need to do this is a basic understanding of the
language.
Third, if you want to override the method in a subclass, all you have
to do is copy and paste that line into your .m and start coding.
Otherwise, you would have to construct the method signature yourself.
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.
Again, calling this method is no different than calling any other
method. The ONLY tricky thing is the use of the singleton. Reading up
on singletons, which are very well documented, would tell you
everything you need to know. But, just in case you didn't they were
kind enough to explain it right at the top!
"There is one shared NSWorkspace object per application. You use the
class method sharedWorkspace to access it. "
And look, they even give an example of how you would call any method
in the class with this singleton
"For example, the following statement uses an NSWorkspace object to
request that a file be opened in the TextEdit application:
[[NSWorkspace sharedWorkspace] openFile:@"/Myfiles/README"
withApplication:@"TextEdit"];"
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,
Aside from the fact that this is pretty much unnecessary for the vast
majority of methods, as explained above, I don't think this could even
be done well usually, as there are usually countless ways to invoke a
method. It all depends on where you get the object and what you are
intending to do. It would be impossible to cover all cases, or often
even the most common cases.
Hell, there are even multiple ways to invoke -launchApplication:
You could technically call it with
NSWorkspace *myWorkspace = [[NSWorkspace alloc]init];
[myWorkspace launchApplication:@"Interface Builder"];
(although you never would), but should the documentation offer this
example as well?
and 2) That you don't actually code "- (BOOL)launchApplication:
(NSString *)appName".
That's true for any method, and if you decided to try typing it in,
even the compiler would tell you what is wrong.
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.
Ok, I totally agree that more examples for nontrivial/special cases
are always welcome. And if you think something could really use an
example, file a bug.
But if you are looking for a reference manual to really complain
about, take a look at something like the old QuickTime API docs :).
That this OP's basically trying to copy the Reference text in his
code shows me that this confusion is very common.
Or that he is just new to the language and could stand to read up on
it a little more before he dives straight in.
And I see 50 other people said the same thing before I could finish
this rant... but whatever.
I am also not trying to be mean at all. It is just that learning a
language always requires a bit of grudge work, and a lot of things can
seem totally unintuitive until you have had enough time to really
learn the conventions.
Adam Leonard
<_< 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