举例swift项目中使用ProgressHUD的库(这里你可以直接使用自己的OC文件)
第一步:直接在项目中导入该库的文件,会有一个提示,Would you lick to configure an Objective-C bridging header 是否创建桥接文件,这里选择Credate Bridging Header,你会发现项目中多了一个Quizzler-Bridging-Header的文件
第二步:在Quizzler-Bridging-Header文件中导入你需要的类文件,这里使用
#import "ProgressHUD.h"
最后一步:在使用的地方直接调用
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { ProgressHUD.show("11111") }
我的第一个导入的时候报错了,提示
ndefined symbols for architecture x86_64,
解决方法,我把Quizzler-Bridging-Header在工程中删除了,又导入了一次,解决了
反之在oc中使用swift的类别
在需要使用的地方,加上这个引用就好了
#import "OCModel.h" #import "SwfitDemo-Swift.h" @implementation OCModel - (instancetype)init { self = [super init]; if (self) { // NSLog(@"OCModel????????????"); //SwiftModel. SwiftModel *modfl = [[SwiftModel alloc]init]; NSLog(@"%@",modfl); } return self; } @end