如何在Swift中采用具有一个属性的Obj-C协议?

时间:2015-12-16 22:50:06

标签: objective-c swift protocols

我有这个Obj-C协议

@protocol MSOutlineViewControllerModelInterface
@property   (weak)  MSOutlineViewController *fatherController ;
@end

我有这个快速的课程

class ModelFileTree : NSObject, MSOutlineViewControllerModelInterface
{
    @objc   weak var fatherController   : MSOutlineViewController?
}

编译器不停地告诉我"类型ModelFileTree不符合协议' MSOutlineViewControllerModelInterface' ...我无法解决任何问题......

1 个答案:

答案 0 :(得分:1)

编译器抱怨,因为它正在将MSOutlineViewControllerMSOutlineViewController?进行比较,这在Swift中是不同的。

试试这个:

@protocol MSOutlineViewControllerModelInterface
    @property   (weak)  MSOutlineViewController * _Nullable fatherController ;
@end