简体   繁体   中英

Error message 'Expected ; after top level declarator ' 'Unknown type name import' with the bridge to use Swift in Objective-C

I Have a message error when I try to add a bridge to use Swift in Objective-C.

Here is my code :

    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
...

Here is my bridge in Swift :

//  Bridging.swift
//  Created by OlostA on 10/06/2016.

import Foundation
import UIKit

@objc class Hello: NSObject {
    func sayHello() {
        print("Hi there!")
    }
}

Here is my Objective-C file :

#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;
    }
}

Any idea?

You have to remove

#import "ScanViewController.swift"

It should be ok then.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM