簡介
在使用Swift編程時,往往我們會用到OC的文件,需要使用其內的方法來滿足我們的需求,所以我們就要使用swift與oc的橋接文件,來引入oc中的頭文件,至此來調用oc中的方法,滿足我們在Swift編程下的需求.
具體步驟
- 1.選中我們的工程,點擊New File -> Header File;
C92E707B-9947-4DE6-895E-58EA5A990B74.png
- 2.點擊Next,為我們的橋接文件命名;
627BA581-0041-4E92-A5A0-71072B24BA55.png
- 3.點擊Create;
A4EA1B0B-CB3B-4ED0-B1A7-D80626D976AB.png
- 4.在Build Setting -> Objective-C Bridging Header添加橋接文件路徑;
973636C7-C4C5-406C-B4D8-36BA05ED84CF.png
- 5.在bridging.h里面引入相應的頭文件;
1DCC183C-E9B1-4F82-B56B-B9B284F3294E.png
- 6.在工程中即可使用;
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
ProgressHUD.showError("錯誤提示")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated. }
}```