我有两个类,基类在Obj-c中,子类在
Swift中.
Obj-c类使用新的XCode 7的轻量级通用功能,定义如下:
@interface BaseController<T: SFObject *> : UIViewController @property(nonatomic,strong) T model; @end
这适用于Obj-c子类.
现在对于Swift,如果我像往常一样定义泛型类型,我会收到以下错误:
Cannot specialize non-generic type ‘BaSEObjcController’.
我的第二课定义如下:
class SwiftController: BaSEObjcController<SFUser> { }
任何帮助,将不胜感激.
谢谢.
解决方法
从
Interacting with Objective-C APIs开始:
NOTE
Aside from these Foundation collection classes,Objective-C
lightweight generics are ignored by Swift. Any other types using
lightweight generics are imported into Swift as if they were
unparameterized.
所以目前这是不可能的.从你可以看到
“生成接口”助手视图,您的Objective-C类被导入
以斯威夫特为例
public class BaseController : UIViewController { public var model: SFObject! }
这也在Apple开发者论坛中讨论过:
> Objective-C generics not visible from Swift?
随意提交增强错误报告!