开发者

iPhone method declaration with two parameters

开发者 https://www.devze.com 2023-02-15 01:56 出处:网络
I\'m fairly new to objetive C and I\'m having trouble declaring a method that takes two parameters. In m开发者_开发百科y .h file I have the following:

I'm fairly new to objetive C and I'm having trouble declaring a method that takes two parameters. In m开发者_开发百科y .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.


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;


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消