tags:

views:

101

answers:

2

Hi, in this sample method/message:

-(void) setNumerator:(int) n {
    numerator = n;
}

What does the (int) mean? It doesn't look like its casting to an int...

A: 

The (int) is a type specifier. It means that the variable (in this case, "n") is of the type "int".

McWafflestix
+10  A: 

int refers to the type of n. When sending the -setNumerator: message, you need to supply an argument. In this case you would supply an argument of type int.

if your method had a definition like:

- (void)setNumerator:(NSNumber *)n {
    NSNumber *newNumerator = [n copy];
    [numerator release];
    numerator = newNumerator;
}

you would then supply an NSNumber when sending -setNumerator:.

Jeff Hellman