ios – Swift是否可以从轻量级通用Objective-c类继承?

前端之家收集整理的这篇文章主要介绍了ios – Swift是否可以从轻量级通用Objective-c类继承?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个类,基类在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?

随意提交增强错误报告!

原文链接:https://www.f2er.com/iOS/335479.html

猜你在找的iOS相关文章