在子类化时混合objective-c和swift [英] mixing objective-c and swift when subclassing

查看:197
本文介绍了在子类化时混合objective-c和swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Swift编写的UIViewController子类,叫做'BaseViewController'。我现在有一个名为'ViewController1'的'旧'视图控制器,用Objective-C编写,我想从'BaseViewController'继承。按照其他建议我导入了'Project-Swift.h'头文件。

I've got a subclass of UIViewController written in Swift called 'BaseViewController'. I now have an 'old' view controller called 'ViewController1' written in Objective-C that I want to inherit from 'BaseViewController'. Following other advice I have imported the 'Project-Swift.h' header file.

当像这样进行子类化时出现问题

My problem occurs when subclassing like this

#import <UIKit/UIKit.h>
#import "MyProject-Swift.h"

@interface ViewController1 : BaseViewController
@end

错误是:

不能使用objc_subclassing-restricted属性对类进行子类化

Cannot subclass a class with objc_subclassing-restricted attribute

它出现在@interface ...行上。

and it appears on the @interface ... line.

推荐答案


你不能继承a Objective-C中的Swift类。

摘自使用Swift与Cocoa和Objective-C

这篇关于在子类化时混合objective-c和swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆