简体   繁体   English

Objective-C桥接标头不适用于Swift文件

[英]Objective-C Bridging Header Not Working for Swift File

I am trying to migrate my project to Swift, and started by making an Objective-C Bridger File filled with #imports to relevant .h files. 我正在尝试将项目迁移到Swift,并开始制作一个将#import填充到相关.h文件的Objective-C Bridger文件。 I've checked exhaustively that the Build Settings options and path are correct. 我已经详尽地检查了“构建设置”选项和路径是否正确。 I created a Swift file for a UITableViewController that looks something like this: 我为UITableViewController创建了一个Swift文件,看起来像这样:

TableViewController.swift TableViewController.swift

class TableViewController {
    var title: String = ""
    var summary: String = ""

    override init(style: UITableViewStyle) {
        super.init(style: style)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        title = UIResources.getString(settingsKey, withSuffix: "title")
        summary = UIResources.getString(settingKey, withSuffix: "summary")
    } 

    ...

}

However, every line starting with the first override result in errors like 但是,从第一个替代开始的每一行都会导致错误,例如

Initializer does not override a designated initializer from its superclass 初始化程序不会覆盖其父类中的指定初始化程序

and

'super' members cannot be referenced in a root class 超级类成员不能在根类中引用

I'm pretty unfamiliar with working with Objective-C, so I'm not sure what I need to change, if anything. 我对使用Objective-C非常不熟悉,因此不确定是否需要更改。 Here is the .h file of the class I imported in the bridging header also. 这也是我在桥接头文件中导入的类的.h文件。 I'm really stumped on this one. 我真的很为难。

TableViewController.h TableViewController.h

#import <UIKit/UIKit.h>

@class TableViewController

@protocol TableViewControllerDelegate <NSObject>

- (void) tableViewControllerDidSave: (UIViewController *)controller forKey:(NSString *)key withNewValue:(id) value;

@end

@interface TableViewController : UITableViewController

@property (strong, nonatomic) id <TableViewControllerDelegate> delegate;
@property (strong, nonatomic) NSString *settingKey;
@property (strong, nonatomic) id stringValue;

@end

I didn't realize I needed to add the type to the class definition 我没有意识到我需要将类型添加到类定义中

class TableViewController : UITableViewController, TableViewControllerDelegate {

That's what you get when you blind trust objectivec2swift.com :P 那就是当您盲目信任objectivec2swift.com时得到的结果:P

I also added the variables and protocol outlined in the .h file to the Swift file. 我还将.h文件中概述的变量和协议添加到了Swift文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM