错误消息'预期;在顶级声明者'之后'未知的类型名称导入'用桥在Objective-C中使用Swift

时间:2016-06-10 09:27:48

标签: ios objective-c swift objective-c-swift-bridge

当我尝试在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;
    }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

你必须删除

#import "ScanViewController.swift"

那应该没问题。