Some notes I have taken based on the short tutorial I found here.
Whenever you see code inside square brackets, you are sending a message to an object or a class.
To create a new object:
id myObject = [NSString string];
The id type means that the myObject variable can refer to any kind of object, so it won't be checked at compile time. However in this case we know the object type will be an NSString, so it could be written it like this:
NSString* myString = [NSString string];
myString is now an NSString variable, so the type will be checked by the compiler. This way of creating an object creates an autorelease object, which will automatically free the object's memory. To create an object using the manual style do it like this:
NSString* myString = [[NSString alloc] init];
If you create an object using the manual alloc style, you need to release the object later:
[myString release];
This (manual) way of object instantiation uses a nested method call (see below). The alloc method called on NSString reserves memory and instantiates an object. The call to init does basic setup, such as creating instance variables. In some cases, you may use a different version of init which takes input:
NSNumber* value = [[NSNumber alloc] initWithFloat:1.0];
Note the asterisk to the right of the object type. All Objective-C object variables are pointers types. The id type is predefined as a pointer type, so there's no need to add the asterisk.
To call a method on an object:
[object method];
or
[object methodWithInput:input];
To return a value:
output = [object methodWithOutput];
or
output = [object methodWithInputAndOutput:input];
To write a nested method, the format is:
[object methodWithInput:[object2 methodWithInput2]];