2

I'm fairly new to objetive C and I'm having trouble declaring a method that takes two parameters. In my .h file I have the following:

-(void)refreshTime:(NSTimeInterval *) absoluteTimeRemainSeconds, (NSDate *) targetDate; 

And in my .m file I have the following:

-(void) refreshTime:(NSTimeInterval *) absoluteTimeRemainInSeconds, (NSDate *) targetDate { 

I want the method two accept two parameters, an NSTimeInterval and an NSDate, but they way I have it now its not working. Can anyone see my error? An help would be greatly appreciated.

3 Answers 3

3

a few things are wrong: first, no commas in between parameters, second the parameter name (and type) go after the colon of what you are doing. An example using your code:

-(void) refreshTime:(NSTimeInterval*)absoluteTimeRemainSeconds usingTargetDate:(NSDate*)targetDate; 
Sign up to request clarification or add additional context in comments.

2 Comments

thank you! so is this the proper way to call the method? [self refreshTime: absoluteTimeRemainInSeconds :targetDate];
@cruzzin No, [self refreshTime:absoluteTimeRemainInSeconds usingTargetDate:targetDate];
1

this would be the good way of doing it

-(void)refreshTime:(NSTimeInterval *) absoluteTimeRemainSeconds targetDate:(NSDate *) targetDate;

and:

-(void)refreshTime:(NSTimeInterval *) absoluteTimeRemainSeconds targetDate:(NSDate *) targetDate{}

You don't need to name the parameters if you don't want to, but you have to leave and space, and not a colon, between two parameters.

Cheers

Comments

0
-(void)refreshTime:(NSTimeInterval *)absoluteTimeRemainSeconds withDate:(NSDate *)targetDate; 

That's it. Obj-C uses named parameters, simply put a space after each one and follow the same syntax. the colon signifies the start of the parameter type and name. You don't even have to use names actually,

-(void)refreshTime:(NSTimeInterval *)absoluteTimeRemainSeconds :(NSDate *)targetDate; 

but it makes thing easier to read with names.

1 Comment

Definitely don't do it like the second example. If you don't name your parameters, anyone else who ever uses your code will curse your name to the heavens. It's like refusing to use newlines and just sticking semicolons with no whitespace between your statements — unidiomatic, bad for readability, and no practical benefit.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.