a function named getTimerInterval returned a NSTimerInterval value
-(NSTimeInterval *)getInterval {
NSTimeInterval interval = 1;
return interval;
}
Xcode warn me
Returning ‘NSTimeInterval’ (aka ‘double’) from a function with
incompatible result type ‘NSTimeInterval *’ (aka ‘double *’); take the
address with &” on the line “return interval”
well, NSInteger type is fine:
-(NSIntefer)getInteger {
NSIntefer result = 1;
return result;
}
as well as return number directly:
-(NSTimeInterval *)getInterval {
return 1;
}
OK, after that calling getInterval function got a warning:
[NSTimer scheduledTimerWithTimeInterval:[self getInterval] target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
Sending ‘NSTimeInterval *’ (aka ‘double *’) to parameter of
incompatible type ‘NSTimeInterval’ (aka ‘double’); dereference with *
I am confused with & and *, where should I have to use & or *?
what’s that meaning actually?
I just know it’s c++ syntax about pointer or something, thank in advanced.
In order to fix the compiler warning, you’d need to return the address of it, like this:
However that is bad as you will return the address on the method’s stack frame which disappears after return. Why not just return it like this:
Which I believe will also fix your other compiler error.