【发布时间】:2009-09-06 21:40:23
【问题描述】:
@protocol Eating
@end
@interface Eat : NSObject<Eating>
{
}
- (id<Eating> *)me;
@end
@implementation Eat
- (id<Eating> *)me { return self; }
@end
在上面的Objective-C代码中,为什么“return self”会导致“Return from incompatible pointer type”警告?什么是不兼容的指针类型以及如何解决?
【问题讨论】:
-
Use @protocol Eating
- 它会让你在这些对象上使用 NSObject 方法,而不仅仅是你需要的方法。
标签: iphone objective-c protocols