iOS swift 开发常用的第三方库

编程入门 行业动态 更新时间:2024-10-24 12:23:15

iOS swift 开发常用的<a href=https://www.elefans.com/category/jswz/34/1770258.html style=第三方库"/>

iOS swift 开发常用的第三方库

在做iOS 开发过程中,我们经常使用到第三方库

例如OC中:AFNetworking、MJRefresh等,这些库我通常会用cocopods来管理。

上述都是OC的,那么swift呢?

其实swift对OC进行了完美兼容,如果依旧使用上述那面也依旧可以使用,我们只需要使用桥接文件并引入路径即可。

 

下面介绍一下swift中常用到的第三方库

  pod 'Alamofire'  // 网络请求管理,== AFNetworkingpod 'MJRefresh'  // 刷新数据和加载数据pod 'Moya'      // 对网络书再次优化使用更简单pod 'SwiftyJSON' // 将请求的返回的数据转json pod 'CLToast'   // 弹框、类似于安卓的吐司pod 'SnapKit'   // 自动布局 == Masonry,使用和Masonry基本一致pod 'SGPagingView' // 类似今日头条首页的布局控件pod 'swiftScan'    // 二维码扫描pod 'IQKeyboardManagerSwift' // 检测键盘弹出和收回,自动上移view,防止输入框被遮挡pod 'Starscream' // websocket         pod 'Then' // Swift语法糖pod 'AlamofireNetworkActivityIndicator' // 监听网络变化pod 'ObjectMapper'  // model 对象(类和结构体)和 JSON 之间转换 pod 'Kingfisher' // 加载网络图片、缓存、下载,== SDWebImagepod 'WisdomHUD'  // 加载提示框,== SVProgresHUDpod 'MLeaksFinder' // 检测循环引用、内存泄漏(腾讯)0代码

1、Alamofire、Moya 的使用

2、MJRefresh的使用和OC一样

3、SwiftyJSON 将数据转成json

//response.data返回的数据(NSData类型)
let jsonData = try JSON(data: response.data)

4、SnapKit自动布局和Then一起使用

let redView = UIView().then { (make) inmake.backgroundColor = .redmake.frame = CGRect(x: 50, y: 50, width: 100, height: 100)self.view.addSubview(make)make.snp.makeConstraints({ (make) inmake.top.left.right.equalTo(0)make.height.equalTo(100)})}

 

5、SGPagingView 使用(今日头条)

// MARK: - 设置选择控制器
extension WGNewsVC {/// 设置 UIprivate func setUpNewsPageUI() {let titles = ["头条","社会","国内","国际","娱乐","体育","军事","科技","财经","时尚"]let types  = ["top","shehui","guonei","guoji","yule","tiyu","junshi","keji","caijing","shishang"]// 标题名称的数组let configuration = SGPageTitleViewConfigure()configuration.indicatorColor = .clear// 标题名称的数组self.pageTitleView = SGPageTitleView(frame: CGRect(x: 0, y: SafeAreaTopHeight, width: Int(kScreenWidth - CGFloat(buttonWidth)), height: 40), delegate: self as SGPageTitleViewDelegate, titleNames: titles, configure: configuration)self.pageTitleView!.backgroundColor = .clearself.pageTitleView?.resetIndicatorColor(UIColor.CSSHex("#323232"))self.pageTitleView?.resetTitleColor(UIColor.CSSHex("#999999"), titleSelectedColor: UIColor.CSSHex("#323232"))self.view.addSubview(self.pageTitleView!)//设置控制器var childvcs = [UIViewController]()for i in 0..<titles.count {let vc  = WGNewListVC()vc.type = types[i]childvcs.append(vc)}self.pageContentView = SGPageContentScrollView(frame: CGRect(x: 0, y: CGFloat(SafeAreaTopHeight + 40), width: kScreenWidth, height: kScreenHeight - CGFloat(SafeAreaTopHeight) - CGFloat(SafeAreaBottomHeight) - 49), parentVC: self, childVCs: childvcs)self.pageContentView!.delegatePageContentScrollView = self as SGPageContentScrollViewDelegateself.pageContentView?.backgroundColor = .clearself.view.addSubview(self.pageContentView!)}
}// MARK: - SGPageTitleViewDelegate
extension WGNewsVC: SGPageTitleViewDelegate, SGPageContentScrollViewDelegate {/// 联动 pageContent 的方法func pageTitleView(_ pageTitleView: SGPageTitleView!, selectedIndex: Int) {self.pageContentView?.setPageContentScrollViewCurrentIndex(selectedIndex)}/// 联动 SGPageTitleView 的方法func pageContentScrollView(_ pageContentView: SGPageContentScrollView!, progress: CGFloat, originalIndex: Int, targetIndex: Int) {self.pageTitleView!.setPageTitleViewWithProgress(progress, originalIndex: originalIndex, targetIndex: targetIndex)}
}

6、swiftScan 扫描二维码

7、IQKeyboardManagerSwift 检测键盘(集成即可,0代码)

8、Starscream websocket 参考资料

9、Then 使用 Swift语法糖

let redView = UIView().then { (make) inmake.backgroundColor = .redmake.frame = CGRect(x: 50, y: 50, width: 100, height: 100)}

10、AlamofireNetworkActivityIndicator 检测网络变化

11、ObjectMapper  model 对象(类和结构体)和 JSON 之间转换

12、Kingfisher 加载、缓存、下载图片==SDWebImage

        imageViews.kf.setImage(with: URL(string: model.thumbnail_pic_s), placeholder: UIImage(named: "qidong"), options: nil, progressBlock: nil) { (reslt) inprint(reslt)}

13、WisdomHUD 提示 == SVProgressHUD

//第一个提示内容,第二个提示时是否可以进行其他操作
WisdomHUD.showLoading(text: "加载中", enable: true)
//关闭弹框
WisdomHUD.dismiss()

.html

14、MLeaksFinder  检测循环引用、内存泄漏(腾讯)0代码

腾讯大神开发的开源库,通过runtime进行消息转发实现的,0代码导入工程即可

给大家举个例子,首先我们在 WGCityVC.swift 创建一个闭包

然后点击WGCityVC.swift上的Cell通过闭包数据返回到首页

然后通过这个闭包,我们可以在想要数据的页面获取这个数据

但是这个时候就能这上图中收到这个些参数

细心的人就会发现这个时候,就会出现iOS swift和OC最经典的问题,循环引用,造成内存泄漏

MLeaksFinder这个时候就会通过Runtime消息转发机制将这个泄漏的类以及泄漏的原因提示给我们,效果图如下

内存泄漏

泄漏原因

整个过程,我就是将MLeaksFinder导入项目中,没有进行其他的代码添加,我们使用时无感的

那么解决这个问题也很容易就是对其进行弱引用

一共有两个方式,1、[unowned self]   和  2、[weak self]

这两种情况都可以解决循环引用的问题,具体使用那个看项目需求,[weak self]相对使用的较多


1、IGListKit [UICollectionView 框架] -> pod 'IGListKit', '~> 2.0.0
2、Realm [移动端数据库] -> pod 'RealmSwift’
3、Moya [抽象网络层] -> pod 'Moya', ‘8.0.0’
4、SwiftyJSON [JSON 解析] -> pod 'SwiftyJSON’
5、Valet [钥匙串帮手] -> pod 'Valet’
6、Firebase Analytics [分析] -> pod 'Firebase/Core’
7、AsyncDisplayKit [异步 UI SDK] -> pod 'AsyncDisplayKit’
8、DZNEmptyDataSet [空状态模式] -> pod 'DZNEmptyDataSet’
9、Chameleon [扁平化颜色框架] -> pod 'ChameleonFramework/Swift', :git => 'ViccAlexander/Chameleon'
10、PermissionScope [iOS 权限框架] -> pod 'PermissionScope’
11、FileKit [文件管理] -> pod 'FileKit', '~> 4.0.0’
12、SwiftyUserDefaults [user defaults 帮手] -> pod 'SwiftyUserDefaults’
13、Kingfisher [下载图片] -> pod 'Kingfisher', '~> 3.0’
14、Hero [自定义试图控制器过渡动画] -> pod 'Hero’
15、Hedwig [发送 email]
16、DeviceKit [设备信息] -> pod 'DeviceKit', '~> 1.0’
17、Charts [图表] -> pod 'Charts’
18、MGSwipeTableCell [可以滑动的 table cells] -> pod 'MGSwipeTableCell’
19、RandomKit [随机生成数字] -> pod 'RandomKit', '~> 3.0.0’
20、ResponseDetective [调适网络请求] -> pod 'ResponseDetective’
21、Onboard [用户指导页] -> pod 'Onboard’
22、Quick + Nimble [BDD 测试] -> pod 'Quick’
23、pod 'Nimble’
24、Natalie [从 storyboard 生成代码]
25、RxSwift [reactive 编程] -> pod 'RxSwift', '~> 3.0’
26、GDPerformanceView [实时 FPS and CPU 用量] -> pod 'GDPerformanceView-Swift', '~> 1.1.0’
27、Alamofire [网络] -> pod 'Alamofire', '~> 4.3’
29、SwiftyStoreKit [app 内购] -> pod 'SwiftyStoreKit’
30、Timepiece [date 帮手] -> pod 'Timepiece’
31、CryptoSwift [加密] -> pod 'CryptoSwift’
32、FSCalendar [日历] -> pod 'FSCalendar’
33、ImageViewer [模仿 Twitter 的图片查看器] -> pod 'ImageViewer’
34、PromiseKit [promises] -> pod 'PromiseKit', '~> 4.0’
35、Ensembles [Core Data 同步] -> pod 'Ensembles’

以上就是开发过程常用到的第三开源库,附上基本使用或者使用连接再次记录一下,希望对大家有所帮助

.html

其实还有很多其他开发库或者框架,下面附上链接🔗,大家可以参考

链接:

 

更多推荐

iOS swift 开发常用的第三方库

本文发布于:2024-03-10 10:16:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1727693.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第三方   常用   iOS   swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!