直接将oc文件拖到项目中,此时Xcode会询问是否生成"{product-mudule-name}-Bridging-Header.h"文件,点击生成后,oc文件会添加到项目中,且会多一个*-Bridging-Header.h文件,在该文件中#import对应oc文件的头文件就可以了
例子:
1.将TestViewController.h和TestViewController.m拖到项目中,生成xxx-Bridging-Header.h文件 (xxx为工程名字)
2.
//xxx-Bridging-Header.h
#import "TestViewController.h"
3.
//ViewController.swift
var test :TestViewController?
test = TestViewController.init()
self.presentViewController(test!, animated:true) { () -> Voidin
print("present")
}
#OC文件中 使用Swift文件
在oc文件中improt "xxx-Swift.h",其中xxx为项目名,例如:
#import "one-Swift.h",one为项目名,注意import的时候不会有提示给你。
之后就可以跟使用其他oc文件一样,用swift文件
参考:http://www.it165.net/pro/html/201501/32179.html
http://blog.csdn.net/huangchentao/article/details/35278663