Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C What are the things in parentheses?

Tags:

objective-c

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...

like image 589
Devoted Avatar asked Nov 23 '25 21:11

Devoted


1 Answers

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:.

like image 196
Jeff Hellman Avatar answered Nov 25 '25 09:11

Jeff Hellman