【发布时间】:2017-09-22 21:04:51
【问题描述】:
我有以下结构。
我得到了符合protocol A 的class B。
protocol A 定义了一个指定的初始化器,即-(instancetype)initWithInt:(int)count。
但是,当我在 class B 中实现标准 -(instancetype)init 并使其使用也在 B 类中实现的指定初始化程序时,我收到警告“指定初始化程序只能在'super'",而我的指定初始化程序(IMO 是 initWithInt)从不调用 super 上的任何指定初始化程序。
@protocol A
{
(instancetype) init;
(instancetype) initWithInt:(NSUInteger)count;
}
@interface B : NSObject <A>
@implementation B
- (instancetype) init {
return [self initWithInt:0];
}
- (instancetype) initWithInt:(NSUInteger)count {
self = [super init];
return self;
}
知道为什么编译器在这种特定情况下会忽略此警告吗?
【问题讨论】:
-
有什么问题?
-
@matt 刚刚更新了问题部分。
-
你打算如何使用这个协议?
标签: objective-c xcode objective-c-runtime