#import "XYZCustomCell.h" #import "XYZCustomView.h" #import "XYZCustomViewController.h"
let myCell = XYZCustomCell() myCell.subtitle = "A custom cell"
Importing Swift into Objective-C
当在OC里调用Swift中的代码时,需要依赖一个xcode自动生成的头文件,这个自动生成的头文件定义了项目中所有的Swift文件,这个头文件的命名为 “xxx-Swift.h” ,xxx为项目的名称,此外就不需要再做任何事情了,你只需要在OC代码里导入这么一个文件,就可以跟没事一样拿任意一个Swift中的代码用了#import “ProductModuleName-Swift.h”
调用Swift代码 | 调用OC代码 | |
Swift代码 | 无需声明 | #import "ProductModuleName-Swift.h” |
OC代码 | 依赖bridging header文件 | #import "Header.h” |
在项目里交叉使用Swift和OC,布布扣,bubuko.com
原文地址:http://blog.csdn.net/huangchentao/article/details/35278663