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. 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:
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. Here is the .h file of the class I imported in the bridging header also. I'm really stumped on this one.
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
I also added the variables and protocol outlined in the .h file to the Swift file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.