与 NSDate 不兼容的指针类型
我不明白为什么这不起作用。以下代码块在 addObject 行引发警告:“从不兼容的指针类型传递'taskWithText:dueDate:'的参数1”
- (id)init{
self = [super init];
if (self) {
taskListArray = [[NSMutableArray alloc] init];
[taskListArray addObject:[AFLTask taskWithText:"@Helloski" dueDate:[NSDate dateWithNaturalLanguageString:@"12/31/12"]]];
}
return self;
}
它是如此简单,我不明白为什么它不起作用。这似乎符合我的方法:
- (id)initWithText:(NSString *)newText dueDate:(NSDate *)newDueDate{
if(self = [super init]){
taskText = [newText retain];
taskDue = [newDueDate retain];
taskCompleted = NO;
}
return self;
}
+ (id)taskWithText:(NSString *)newText dueDate:(NSDate *)newDueDate{
return [[[AFLTask alloc] initWithText:newText dueDate:newDueDate] autorelease];
}
这是怎么回事?我对 Objective-C 还很陌生(但不是一般的编程),所以我仍在尝试围绕指针进行思考——但这不应该起作用吗?
I can't see why this doesn't work. The following code block throws a warning at the addObject line: "Passing argument 1 of 'taskWithText:dueDate:' from incompatible pointer type"
- (id)init{
self = [super init];
if (self) {
taskListArray = [[NSMutableArray alloc] init];
[taskListArray addObject:[AFLTask taskWithText:"@Helloski" dueDate:[NSDate dateWithNaturalLanguageString:@"12/31/12"]]];
}
return self;
}
It's so simple I don't see why it doesn't work. It seems to match my method:
- (id)initWithText:(NSString *)newText dueDate:(NSDate *)newDueDate{
if(self = [super init]){
taskText = [newText retain];
taskDue = [newDueDate retain];
taskCompleted = NO;
}
return self;
}
+ (id)taskWithText:(NSString *)newText dueDate:(NSDate *)newDueDate{
return [[[AFLTask alloc] initWithText:newText dueDate:newDueDate] autorelease];
}
What is going on here? I'm pretty new to Objective-C (but not programming in general) and so I'm still trying to wrap my head around pointers -- but shouldn't this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你会踢自己一脚:
应该是
You're going to kick yourself:
should be