swift pod第三方OC库使用use_frameworks!导致#import提示无法找到头文件
2017-03-13 15:14
756 查看
以MBProgressHUD为例子
swift中Podfile文件一般都会加上use_frameworks! 这样就可以直接通过import MBProgressHUD来访问MBProgressHUD中的方法了
这个时候如果我们想要给MBProgressHUD添加一些方法,一般会使用category,在创建category的时候#import "MBProgressHUD.h"
提示无法找到对应的头文件
导致这个问题的原因是use_frameworks!会把我们导入的第三方库转换成framework
swift中访问framework的方法:
Objective-C中访问framework的方法:
同样的道理,如果我们想在swift中使用AFNetWorking,然后又想给AF初始化一些参数,可以使用@import AFNetworking; 附AFNetworking中利用runtime动态acceptableContentTypes的方法
swift中Podfile文件一般都会加上use_frameworks! 这样就可以直接通过import MBProgressHUD来访问MBProgressHUD中的方法了
这个时候如果我们想要给MBProgressHUD添加一些方法,一般会使用category,在创建category的时候#import "MBProgressHUD.h"
提示无法找到对应的头文件
导致这个问题的原因是use_frameworks!会把我们导入的第三方库转换成framework
swift中访问framework的方法:
import MBProgressHUD
Objective-C中访问framework的方法:
@import MBProgressHUD;
同样的道理,如果我们想在swift中使用AFNetWorking,然后又想给AF初始化一些参数,可以使用@import AFNetworking; 附AFNetworking中利用runtime动态acceptableContentTypes的方法
@implementation AFJSONResponseSerializer (Serializer) +(void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Method ovr_initMethod = class_getInstanceMethod([self class], @selector(init)); Method swz_initMethod = class_getInstanceMethod([self class], @selector(swizzlingForSetSerializer_init)); method_exchangeImplementations(ovr_initMethod, swz_initMethod); }); } - (id) swizzlingForSetSerializer_init { id swz_self = [self swizzlingForSetSerializer_init]; if (swz_self && [swz_self isKindOfClass:[AFJSONResponseSerializer class]]) { //start tiny NSSet * contentSet = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/plain", @"text/html", nil]; [swz_self setValue:contentSet forKey:@"acceptableContentTypes"]; } else { NSLog(@"AFJSONResponseSerializer+Serializer kvc get AFJSONResponseSerializer error"); } // return swz_self; }
相关文章推荐
- SHELL syntax error:unexpected end of file 提示错误; windows下修改linux文件导致linux文件无法使用
- OC使用use_frameworks!添加swift,其他库头文件不提示
- 系统搜索功能不能使用,弹出“无法找到运行搜索助理需要的一个文件”
- IIS不能启动,提示"另一程序正在使用此文件,进程无法访问"
- sql2000备份的数据库还原到sql2005后,选择“数据库关系图”提示:此数据库没有有效所有者,因此无法安装数据库关系图支持对象。若要继续,请首先使用“数据库属性”对话框的“文件”页或 ALTER AUTHORIZATION 语句将数据库所
- 无法找到monitor.jse脚本文件导致桌面所有链接失效
- 打开我的电脑,双击某个盘可访问,但双击有的盘则提示windows 无法找到Iexplores.exe,该程序用于打开"文件"类型的文件
- 复制数据库时,必须要先停止Sql Server服务,才能复制.否则提示:无法复制,文件正在被另一个人或程序使用.
- 卸载Sql Server 提示无法找到安装日志文件解决办法
- IIS “另一个程序正在使用此文件,进程无法访问。”错误提示的解决办法
- Visual Assist X尽量避免在非英文目录下使用,否则可能由于文件路径不能识别而导致不能进行提示
- iis提示“另一个程序正在使用此文件,进程无法访问”
- iis提示“另一个程序正在使用此文件,进程无法访问”解决办法
- iis提示“另一个程序正在使用此文件,进程无法访问”解决办法
- IIS出现“另一个程序正在使用此文件,进程无法访问。”错误提示的解决办法
- 在IE6下打开PDF 提示 无法找到文件的问题
- 在iis中注册asp.net 2.0 解决打开aspx文件提示无法找到该页
- windows2003 IIS 服务启动失败,提示‘另一个程序正在使用此文件,进程无法访问',解决方法!
- 关于在英创em9161板上使用ADO.net连接远程数据库提示 “无法找到 PInvoke dll"dbnetlib.dll"”问题解决方法
- 安装Office 2007问题 Office2007提示无法找到Office.Zh-CN/……之类的文件,