当我尝试在Objective-C中添加桥接以使用Swift时,我发生了一条消息错误。
这是我的代码:
import UIKit
@objc class ScanViewController : UIViewController, IRLScannerViewControllerDelegate
{
var scan: Int = 0 //FIXME:delegate to put in swift
var category: String = "" //FIXME:delegate to put in swift
...
这是我在斯威夫特的桥梁:
// Bridging.swift
// Created by OlostA on 10/06/2016.
import Foundation
import UIKit
@objc class Hello: NSObject {
func sayHello() {
print("Hi there!")
}
}
这是我的Objective-C文件:
#import "CategoryViewController.h"
#import "ScanViewController.swift"
#import "GoFact-Swift.h"
@interface CategoryViewController ()
@end
@implementation CategoryViewController
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"yourSegueIdentifier"])
{
ScanViewController *destViewController = segue.destinationViewController;
destViewController.category = sender;
}
}
有什么想法吗?
答案 0 :(得分:5)
你必须删除
#import "ScanViewController.swift"
那应该没问题。