In this line:
- (id)initWithName:(NSString *)name;
(NSString *)
is simply the type of the argument - a string object, which is the NSString class in Cocoa. In Objective-C you're always dealing with object references (pointers), so the "*" indicates that the argument is a reference to an NSString
object.
In this example:
person.height = (NSObject *)something;
something a little different is happening: (NSObject *)
is again specifying a type, but this time it's a "type casting" operation -- what this means is to take the "something" object reference (which could be an NSString
, NSNumber
, or ...) and treat it as a reference to an NSObject
.
update -
When talking about Objective-C objects (as opposed to primitive types like int or float), everything's ultimately a pointer, so the cast operation means "take this pointer an X
and treat it as if it's pointing to a Y
". For example, if you have a container class (like NSArray
) that holds generic NSObject
s, but you know that the the objects are actually strings, you might say:
NSString *myString = (NSString *)[myArray objectAtIndex:0];
which means "retrieve the first object from the array, treating it as a string".
The cast is not actually converting the value, it's just a way of saying to the compiler "hey, I know that I'm assigning an X to a Y here, so don't give me a warning about it".