0

我的对象声明如下:

我的.h

@interface My:NSObject{
    NSTimeInterval time;
}
@property (assign) NSTimeInterval time;
@end

我的

@implementation My
@synthesize time;
@end

代码中的某处:

-(NSTimeInterval)getTimeInterval:(NSString*)timeStr
{
    NSTimeInterval interval;
    //some code
    return interval;
}


-(void) func:(NSString*)timeInterval
{
    My *my = [[My alloc] init];
    my.time = [self getTimeInterval:timeInterval];
}

在行中

my.time = [self getTimeInterval:timeInterval];

我收到错误:“'setTime' 的参数 1 的类型不兼容”

谁能告诉我问题出在哪里?

4

2 回答 2

0

您的函数“getTimeInterval”将字符串作为参数,我假设您将 NSTimeInterval / double 传递给函数,从而导致警告。你应该改变你的

-(NSTimeInterval)getTimeInterval:(NSString*)timeStr 

取一个 NSTimerInterval 的参数(这只是一种花哨的说法)。如果您的意思是传递一个时间的字符串表示并返回一个 NSTimeInterval,那么您的代码中有一个错误,应该将 timeInterval 变量更改为包含您的时间的字符串变量。

于 2011-03-07T10:30:19.207 回答
0

这在很多方面看起来都很奇怪。

我很确定 NSTimeInterval 只是 double 的 typedef,这使得将属性定义为 assign 是错误的。删除它,看看它是否有效。

于 2011-03-07T10:31:44.783 回答