• 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: More fun, curious obj-c questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More fun, curious obj-c questions


  • Subject: Re: More fun, curious obj-c questions
  • From: Andreas Monitzer <email@hidden>
  • Date: Tue, 29 May 2001 12:19:47 +0200

On Tuesday, May 29, 2001, at 11:57 , Scott wrote:

Points:
* Okay, confusion setting in. The following declaration makes sense in
it's own circumstance:

-(void) setWidth:(float)width height:(float)height;

but the abstraction loses consistency in:

-(void) mouseDown:(NSEvent *)theEvent;

Here, the method name has nothing to do with the parameter passed, where in
the first example, setWidth:height:, the words setWidth have everything to
do with describing the first parameter.

theEvent contains information about the mouseDown (where, when, how many, modifiers...).

My ambiguity meter just blew up and landed across the room in pieces.

Why not just declare the first as:

-(void) setWidthHeight:(float)width :(float)height;

Then, when I call the method, it looks like:

[myRect setWidthHeight:10.0 :10.5];

Much more readable to me.

Yes, it means "set the height of the width to 10.0. But what I don't understand is this second parameter.

Or, would this be correct/possible?

-(void)setBounds width:(float)width height:(float)height;
^

Would be nice, but spaces are not allowed in selectors.


* Are Obj-c method calls ordered as to parameters?
Is:

-(void) setTop:(float)top left:(float)left bottom:(float)bottom
right:(float)right;

The same as:

-(void) setTop:(float)top bottom:(float)bottom left:(float)left
right:(float)right;

no

* So, when Obj-c gets compiled, does this mean there's an extra layer to
the calling structure? It sounds like a message is interpreted before the
runtime system figures out where to direct the pc.

Yes, the selectors are resolved at runtime (which also makes converting strings to selectors and calling them possible).

* the "+" vs. "-" thing:
I can't for the life of me conceive of a time when I would care about the
difference btwn class and instance methods, but I'm sure someone put it in
there for a reason. Anyone got some examples of when I would use a class
method over an instance method?

[[NSWorkspace sharedWorkspace] openFile:@"/mach_kernel"];

NSWorkspace is a class
sharedWorkspace is a class method, which returns the central instance of NSWorkspace (there's only one per application)
openFile: is a instance method of NSWorkspace

* Doc site:
I'm creating a site with tips, tricks, hints, general info for c++->obj-c
converts like myself. If anyone has any additional insights on how to
approach obj-c with a c++ mentality, please send them to me at:

mailto:email@hidden

It's much more complicated to go ObjC -> C++ than the other way round. I realized this when working at a C++-project in school. Suddenly, all dynamism was gone...

Also, please send me any GOTCHAs -- i.e. Stuff you found frustrating because
it worked differently than you expected, whether it be re: obj-c syntax,
mindset required for obj-c or the IB or PB interaces. Come on, there has to
be something that got you when you were learning. <g> Come on, what was it?

Can't think of anything right now... The Java Bridge was very complicated to learn, but I've written a tutorial on that, it should be no problem for others now.

andy
--
Description forthcoming.


References: 
 >More fun, curious obj-c questions (From: Scott <email@hidden>)

  • Prev by Date: More fun, curious obj-c questions
  • Next by Date: 2 Dockling Problems
  • Previous by thread: More fun, curious obj-c questions
  • Next by thread: Re: More fun, curious obj-c questions
  • Index(es):
    • Date
    • Thread