How can I import File.swift into ViewController.h and vice versa?

I tried to create a .swift file to change the color in the navigation bar, but when I tried to import File.swift into the ViewController, it shows me an error.

------- code --------

//Esta clase se creo para dar color a la NavViewController por medio de su valor en RGB import UIKit class NavViewController: UINavigationController { override func viewDidLoad() { //Se divide el valor RGB entre 255.0 UINavigationBar.appearance().barTintColor = UIColor(red: 110/255.0, green: 192/255.0, blue: 238/255.0, alpha: 1.0) super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ 

the error says: Expected; after the top level announcement

+5
source share
2 answers

Here are the official docs from Apple: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

Use Swift in Objective-C

you need to rely on the Xcode-generated header file to expose these files to Objective-C. This auto-generated file is an Objective-C header that declares Swift interfaces in your target environment.

  • In the target building settings application, you can find your Product Module Name .

  • In the Objective-C #import "<ProductModuleName>-Swift.h" file #import "<ProductModuleName>-Swift.h"

Use Objective-C in Swift

  • Create a bridge file by choosing File> New> File> (iOS or OS X)> Source> Header File. Naming convention <ProductModuleName>-Bridging-Header.h (Alternatively, you can create a Swift project in pure Objective-C , and Xcode will ask if you need a bridge file)

  • Import the Objective-C file that you want to use in the bridge file.

  • Use it directly in Swift .

+3
source

In appName-Bridging-Header.h you need to import the required .h file and they will be available in fast code

And in the Objective-C file, you need to import the generated module_name-Swift.h , which contains all the quick access classes. This way, quick classes will be available in object c.

+1
source

All Articles