| Sign In/My Account | View Cart |
| Article: |
The Objective-C Language | |
| Subject: | Returned Data types of methods | |
| Date: | 2001-07-04 19:49:13 | |
| From: | bigboytoddy | |
|
Response to: Definitions of Interface/Implementation, it is in error to say ObjC defines these in seperate files.
|
||
|
In fact, I believe that the id reference is always 'self', unless it is explicitely changed, say as returning a substitute class or even having it poseAs?, so if this true (I'm having a brain fart right now) it would conclude that in class methods '+' that would be indeed the class itself, and in instance methods '-', self would be the instance of course. I stand corrected if I'm wrong, wouldn't that explain it clearer? LOL
|
||
Showing messages 1 through 2 of 2.
In the past, and currently the setIVar has always been assumed, and for reasons doing with Interface Builder, the method say for iVars defined in the @interface as
@interface YourClass : NSObject
{
id someVar;
id someOtherVar;
}
// no need to define setters in the interface,
// by default they are already called if you
// define them in the implementation, the runtime
// (folks, you should read the runtime stuff if
// you have not already, those low level C functions
// will really clear things up for you about how
// things are done, management of selectors in
// the class structure, creating new methods on
// the fly if you wanted, say for behavioral
// based systems, adding interfaces to live
// classes, all kinds of cool stuff) will call
// the automagically, maybe that has been removed... but back to the real issue of naming.
@
@implementation
- setSomeVar
{ // do something useful, gets called upon initing
// allowing setup of vars... I think this still
// exists, yet I could be so old and decrepid
// NeXT/Apple may have taken this out
}
- setSomeOtherVar
{ // same as above, gets called automagically
}
@end
Now I hope Apple has stopped this, for obvious
reasons, it was undocumented and also really
messed things up when you wrote code, and didn't
know the side effects.
Basically it boils down to this, and is related
to the ramblings above. In Smalltalk, there
is a practice of naming (and it is good) for
getters and setters, 1/2 of which is follwed
for them most part in the ObjC community. I
highly recommend folks do this also...
The colon is part of the naming convention, yet
is really useful as a 'setter' word, indicating
something is being set... It is pretty obvious
when reading code that something is an iVar, without
explicitely telling them in the name, we all read
enough of it eventually to know with naming things
right, a method named
- center // would return the center of an object
- center: newCenter // would set same
That is it, instead of this stuff like
- getCenter // which I still see in code reviews
- setCenter: newCenter // which is redundant
That is it, tangential stuff aside, this is the
whole of my point, the ':' is part of the selector
definition, and unfortunately we often only use
it to visually seperate the selector from the
variables, in reality it is PART of the selector
itself and has value, especially in such obvious
settings.
Best wishes, I do hope this helps.
\t