zoukankan      html  css  js  c++  java
  • 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;
    }
    
    
  • 相关阅读:
    系统信息查看命令
    item pipeline 实例:爬取360摄像图片
    scrapy之 downloader middleware
    scrapy 中用selector来提取数据的用法
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/6542985.html
Copyright © 2011-2022 走看看