Devoted
Devoted

Reputation: 183573

Objective-C What are the things in parentheses?

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

Upvotes: 2

Views: 290

Answers (2)

Jeff Hellman
Jeff Hellman

Reputation: 2117

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

Upvotes: 10

Paul Sonier
Paul Sonier

Reputation: 39510

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

Upvotes: 0

Related Questions