swift中CocoaPods的使用
CocoaPods安装就不必说了,网上资料大把,做过iOS开发的也应该都会安装,但转swift后用原来OC的podfile的格式就不行了,比如我pod install swift界中的masonry,SnapKit
target 'waterelephantDemo' do
use_frameworks!
pod 'SnapKit', '~> 4.0.0'
end
顺便贴上SnapKit的使用方法,跟masonry差不太多,用过的基本都能一分钟上手
let imageView = UIImageView()
self.view.addSubview(imageView)
imageView.image = UIImage(named:"homepage_picuser")
imageView.snp.makeConstraints { (make) in
make.width.height.equalTo(104)
make.centerX.equalTo(self.view)
make.top.equalTo(87)
}
CocoaPods中使用OC库
需要新建 OderApprove-Bridging-Header 文件并在Objective-C Bridging header中配置该文件的相对路径,如图

然后在该文件中引入相应OC三方库的头文件
#ifndef OderApprove_Bridging_Header_h
#define OderApprove_Bridging_Header_h
#endif /* OderApprove_Bridging_Header_h */
#import "JPUSHService.h"
#import "MJRefresh.h"
// iOS10注册APNs所需头文件
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#import "UIImage+QRCodeImage.h"
#endif
如import导入报错找不到该文件,请在USer Header Search Paths中添加${SRCROOT}并设置为recursive,如下图

设置完成后在OderApprove-Bridging-Header.h文件中正常#import "MJRefresh.h"即可。
网友评论