I tried to make a file .swift to change the color from the navigation bar in a but when I tried to import the File.swift in 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.
}
*/
error says : Expected ; after top level declaration
Here is the official documents 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 an Xcode-generated header file to expose those files to Objective-C. This automatically generated file is an Objective-C header that declares the Swift interfaces in your target.
In the app target building settings
, you could find your Product Module Name
.
In Objective-C file, #import "<ProductModuleName>-Swift.h"
Use Objective-C in Swift
Create bridge file, Choosing File > New > File > (iOS or OS X) > Source > Header File. The naming convention is <ProductModuleName>-Bridging-Header.h
(Also, you could create a Swift
in pure Objective-C
project and XCode will prompt whether you need a bridge file)
Import Objective-C file you want to use into the bridge file.
Use it directly in Swift Code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With