【问题标题】:Error message 'Expected ; after top level declarator ' 'Unknown type name import' with the bridge to use Swift in Objective-C错误消息'预期;在顶级声明符''未知类型名称导入'之后,在 Objective-C 中使用 Swift 的桥梁
【发布时间】:2016-06-10 09:27:48
【问题描述】:

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

有什么想法吗?

【问题讨论】:

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


    【解决方案1】:

    你必须删除

    #import "ScanViewController.swift"
    

    那应该没问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 2016-10-21
      • 1970-01-01
      • 2018-11-02
      • 1970-01-01
      • 2015-10-18
      • 2016-12-28
      相关资源
      最近更新 更多