NStimeInterval property error
开发者_JS百科My object declared as follows:
my.h
@interface My:NSObject{
NSTimeInterval time;
}
@property (assign) NSTimeInterval time;
@end
my.m
@implementation My
@synthesize time;
@end
somewhere in the code:
-(NSTimeInterval)getTimeInterval:(NSString*)timeStr
{
NSTimeInterval interval;
//some code
return interval;
}
-(void) func:(NSString*)timeInterval
{
My *my = [[My alloc] init];
my.time = [self getTimeInterval:timeInterval];
}
in the line
my.time = [self getTimeInterval:timeInterval];
i get error: "incompatible type for argument 1 of 'setTime' "
Can anyone tell me where is the problem?
You function "getTimeInterval" takes a string as an argument, and I presume that you're passing in a NSTimeInterval / double into the function, causing the warning. You should change your
-(NSTimeInterval)getTimeInterval:(NSString*)timeStr
To take a parameter of NSTimerInterval (which is just a fancy way to say double). If you mean to pass in a string representation of a time and get a NSTimeInterval back, you have a bug in your code, and should change timeInterval variable to a string variable containing your time instead.
This seems strange in so many ways.
I'm pretty sure NSTimeInterval is a just a typedef for double, which makes the definition of the property as assign to be wrong. Remove it and see if it works.
精彩评论