It's based on the "concept of messaging between objects."
objects, being classes? I think.
So a message is [someObject doSomething] or rather, [receiver selector].
Messages can include arbitrary arguments and can return values. Any message can be sent to any receiver. If a receiver doesn't understand the message, a runtime error occurs (this is stupid. Makes it more likely for a mistake to be made as a typo...)
messaging ≠ function call. Hence the odd syntax.
The basic object, is an id. It is a pointer to an object. An id object defined as
id anObject;
will be nil. selectors can be sent to this nil pointer without returning errors, however, values returned from the message to nil is undefined in some cases.
id should be avoided, and used only when very little info is known.
NSString is a string. I need a list of these NS thingies.
More ObjC types:
SEL - used to store selectors
IMP - used to store pointers to the C function that implement messages (wha...?)
Class - use to store pointers to ObjC class objects.
id - used to store pointers to arbitrary ObjC objects.
BOOL - used to store boolean constants YES and NO.
note: caps is important in ObjC.
Class interfaces are defined:
instance variables:
@public/@private/@protected type variable;
Instance methods:
- (returnType)methodName:(inputType)inputParameter;
Class methods:
+ (returnType)methodName:(inputType)inputParameter with:(inputType2)inputParam2;
: is part of the method name, so the above two method's real names would be the following.
methodName:
&
methodName:with:
the with could be left out of the second one, but this would result in:
methodName:: -- note the double colon.
Also, note that given - (returnType)methodName; and - (returnType)methodName:(inputType)inputParameter;
methodName is different from methodName:
A method's name = message it handles, and methods are invoked upon receipt of a message. They are selectors~ Message names can be stored as a variable with the type SEL. ie:
SEL aSelector;
aSelector = @selector(setObject:forKey:);
This can then be passed as an argument
-(void)performSelector:(SEL)aSelector withObject:(id)anObject;
Classes are represented at runtime by an object...
categories... are like Java's... thingiemabobbers. They let you add methods to a class, without requiring the source code for the class that is being extended or recompiled. The limitation, however, is that, unlike subclasses, you can't add instance variables.
@interface classname (categoryname)
@implementation classname (categoryname)
objects, being classes? I think.
So a message is [someObject doSomething] or rather, [receiver selector].
Messages can include arbitrary arguments and can return values. Any message can be sent to any receiver. If a receiver doesn't understand the message, a runtime error occurs (this is stupid. Makes it more likely for a mistake to be made as a typo...)
messaging ≠ function call. Hence the odd syntax.
The basic object, is an id. It is a pointer to an object. An id object defined as
id anObject;
will be nil. selectors can be sent to this nil pointer without returning errors, however, values returned from the message to nil is undefined in some cases.
id should be avoided, and used only when very little info is known.
NSString is a string. I need a list of these NS thingies.
More ObjC types:
SEL - used to store selectors
IMP - used to store pointers to the C function that implement messages (wha...?)
Class - use to store pointers to ObjC class objects.
id - used to store pointers to arbitrary ObjC objects.
BOOL - used to store boolean constants YES and NO.
note: caps is important in ObjC.
Class interfaces are defined:
@interface CLASS-NAME : SUPER-CLASS-NAME
{
INSTANCE VARIABLES
}
METHOD DECLARATIONS
@end
instance variables:
@public/@private/@protected type variable;
Instance methods:
- (returnType)methodName:(inputType)inputParameter;
Class methods:
+ (returnType)methodName:(inputType)inputParameter with:(inputType2)inputParam2;
: is part of the method name, so the above two method's real names would be the following.
methodName:
&
methodName:with:
the with could be left out of the second one, but this would result in:
methodName:: -- note the double colon.
Also, note that given - (returnType)methodName; and - (returnType)methodName:(inputType)inputParameter;
methodName is different from methodName:
A method's name = message it handles, and methods are invoked upon receipt of a message. They are selectors~ Message names can be stored as a variable with the type SEL. ie:
SEL aSelector;
aSelector = @selector(setObject:forKey:);
This can then be passed as an argument
-(void)performSelector:(SEL)aSelector withObject:(id)anObject;
Classes are represented at runtime by an object...
categories... are like Java's... thingiemabobbers. They let you add methods to a class, without requiring the source code for the class that is being extended or recompiled. The limitation, however, is that, unlike subclasses, you can't add instance variables.
@interface classname (categoryname)
@implementation classname (categoryname)