• swift pod第三方OC库使用use_frameworks!导致#import提示无法找到头文件


    以MBProgressHUD为例子
    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;
    }
    
    
  • 相关阅读:
    js获取下拉框的值
    根据SNP的位置从基因组提取上下游序列
    PCA分析的疑问
    os删除文件或者文件夹
    python scipy包进行GO富集分析p值计算
    生物信息等级的划分
    docker笔记
    GATK4注意事项
    centos7修改yum源为阿里镜像
    idea如何通过数据库生成实体类
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/6542985.html
Copyright © 2020-2023  润新知