1

当我尝试添加桥以在 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
...

这是我在 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;
    }
}

任何的想法?

4

1 回答 1

5

你必须删除

#import "ScanViewController.swift"

那应该没问题。

于 2016-06-10T09:29:59.333 回答