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;
    }
    
    
  • 相关阅读:
    codeforces 659F F. Polycarp and Hay(并查集+bfs)
    codeforces 659B B. Qualifying Contest(水题+sort)
    codeforces 659E E. New Reform(图论)
    codeforces 659D D. Bicycle Race(水题)
    sql_mode值的含义
    MySQL Query Cache
    Orchestrator安装
    脚本VIP更改为keepalive
    MHA软件下载地址
    MySQL中的事件调度器EVENT
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/6542985.html
Copyright © 2011-2022 走看看