項(xiàng)目開發(fā)中OC中會(huì)使用到Swift文件搀别,也可能在Swift項(xiàng)目中調(diào)用OC文件晚岭,兩種方式略有不同:
OC調(diào)用Swift文件
1.OC項(xiàng)目中嗤无,新建Swift文件會(huì)讓選擇創(chuàng)建頭文件,ProductName(項(xiàng)目名稱)-Bridging-Header.h
2.Swift調(diào)用需要設(shè)置Module為Yes壶愤,Product Module Name 默認(rèn)是項(xiàng)目名稱:
3.項(xiàng)目需要調(diào)用Swift文件導(dǎo)入OCDemo-Swift.h文件:
<pre><code>`
import "ViewController.h"
import "OCDemo-Swift.h"
@interface ViewController ()
@end
@implementation ViewController
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Person *person = [[Person alloc] init];
NSLog(@"FlyElephant---%@",person.personName);
}(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end`</code></pre>
Swift調(diào)用OC文件
1.新建OC文件會(huì)提示創(chuàng)建頭文件:
2.在頭文件中導(dǎo)入新創(chuàng)建的文件即可:
<pre><code>`