我正在尝试使用轻量级通用模板实现堆栈类。但是代码无法编译,因为Xcode找不到“ObjectType”的定义。
@implementation Stack
- (ObjectType)popObject !!!!!!!!!Expected a type
{
return self.allObjects.firstObject;
}
@end
这很奇怪,因为标题声明并不会生成任何错误。
@interface Stack<__covariant ObjectType> : NSObject
- (ObjectType)popObject;
@property (nonatomic, readonly) NSArray<ObjectType> *allObjects;
@end
我可以通过将ObjectType
更改为id
使其工作。
有更好的方法来解决这个错误吗?