每个ios开发者都应该知道Top 10 Swift三方库
来源:互联网 发布:身边嫁有钱人知乎 编辑:程序博客网 时间:2024/05/22 04:52
1.Alamofire
当你想要抽象简化App中的网络请求时,Alamofire是你需要的,Alamofire是一个Http网络请求库,构建在NSURLSession和基础URL加载系统之上,它用简单优雅的接口很好的封装了网络请求。
// Making a GET requestAlamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"]) .responseJSON { response in print(response.request) // original URL request print(response.response) // URL response print(response.data) // server data print(response.result) // result of response serialization if let JSON = response.result.value { print("JSON: \(JSON)") } }
2.SwiftyJSON
swift的Explicit types(显示类型)可以确保我们不会在代码中犯错和出现bug。但是有时处理起来还是比较麻烦,特别是和JSON打交道的时候。幸运的是,SwiftyJSON提供了可读性更好的方式帮我们处理JSON数据。还提供了可选的自动解析!
// Typical JSON handlingif let statusesArray = try? NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as? [[String: AnyObject]], let user = statusesArray[0]["user"] as? [String: AnyObject], let username = user["name"] as? String { // Finally we got the username}// With SwiftyJSONlet json = JSON(data: dataFromNetworking)if let userName = json[0]["user"]["name"].string { //Now you got your value}
SwiftyJson也可以很好的和Alamofire配合使用。
Alamofire.request(.GET, url).validate().responseJSON { response in switch response.result { case .Success: if let value = response.result.value { let json = JSON(value) print("JSON: \(json)") } case .Failure(let error): print(error) }}
3.ObjectMapper
如果你写过一个通过API获取信息的app,你可能需要花大量时间写代码把你的响应结果映射为你的object。ObjectMapper可以帮你把JSON格式响应结果转换成你的model对象,反之亦然。换句话说,它帮你把JSON映射成对象,也可以把对象转换成JSON。嵌套的对象也支持。
// Temperature class that conforms to Mappable protocolstruct Temperature: Mappable { var celsius: Double? var fahrenheit: Double? init?(_ map: Map) { } mutating func mapping(map: Map) { celsius map["celsius"] fahrenheit map["fahrenheit"] }}
AlamofireObjectMapper也值得提一下,一个Alamofire的扩展使用ObjectMapper将JSON响应数据转换成swift对象。
4.Quick
Quick是一个行为驱动(BDD)开发框架,它的灵感来自于
RSpec,Specta, 和Ginkgo。配合Nimble一起使用,Nimble是一个测试匹配框架。
// Documentation directory specclass TableOfContentsSpec: QuickSpec { override func spec() { describe("the 'Documentation' directory") { it("has everything you need to get started") { let sections = Directory("Documentation").sections expect(sections).to(contain("Organized Tests with Quick Examples and Example Groups")) expect(sections).to(contain("Installing Quick")) } context("if it doesn't have what you're looking for") { it("needs to be updated") { let you = You(awesome: true) expect{you.submittedAnIssue}.toEventually(beTruthy()) } } } }}
5.Eureka
Eureka可以帮你简单优雅的实现动态table-view表单。它由rows,sections和forms组成。如果你的app包含大量表单,Eureka可以真正帮你节省时间。
// Creating a formclass CustomCellsController : FormViewController { override func viewDidLoad() { super.viewDidLoad() form +++ Section("Custom cells") <<< WeekDayRow(){ $0.value = [.Monday, .Wednesday, .Friday] } <<< TextFloatLabelRow() { $0.title = "Float Label Row, type something to see.." } }}
6.RxSwift
RxSwift是一个基于Swift的的函数式响应编程框架。更具体点,RxSwift是是Rx的一个Swift语言版本(还有Java版本RxJava,js->RxJs)它的目标是让异步和事件数据流操作更简单。KVO observing, async operations and delegates are all unified under abstraction of sequence(还没来的及学习掩面哭),如果你已经使用过ReactiveCocoa,你接受起来会比较简单(都是函数式编程思想)
// Combine first and last name sequences, and bind the resulting string to labelcombineLatest(firstName.rx_text, lastName.rx_text) { $0 + " " + $1 } .map { "Greeting \($0)" } .bindTo(greetingLabel.rx_text)
7.SnapKit
SnapKit是一个用少量代码写出不丢可读性auto layout的AutoLayout库。
// Resizing and centering subview in its superviewlet box = UIView()let container = UIView()container.addSubview(box)box.snp_makeConstraints { (make) Void in make.size.equalTo(50) make.center.equalTo(container)}
8.Spring
spring是一个可以帮你用代码或者直接在Storybard创建动画的动画库,在Storyboard你可以用runtime(通过设置IBInspectable属性)来创建动画,Spring已经成长为一个全面发展的动画库 支持很多已经存在的动画。
// Usage with codelayer.animation = "wobble"layer.animate()
9.Kingfisher
Kingfisher是一个轻量的下载和缓存网络图片库。下载和缓存是异步进行操作,已经下载好的图片会缓存在内存和本地,极大得提高app的体验。
// Basic example of downloading and caching an imageimageView.kf_setImageWithURL(NSURL(string: "http://your_image_url.png")!)
10.CoreStore
CoreStore是一个基于Core Data的封装库。它的目标是安全优雅和Core Data进行交互。CoreStore的API提供了常用的有效的方法让你和你的数据库进行交互。
// Storing a person entityCoreStore.beginAsynchronous { (transaction) Void in let person = transaction.create(Into(MyPersonEntity)) person.name = "John Smith" person.age = 42 transaction.commit { (result) Void in switch result { case .Success(let hasChanges): print("success!") case .Failure(let error): print(error) } }}
- 每个ios开发者都应该知道Top 10 Swift三方库
- 每个ios开发者都应该知道Top 10 Swift三方库
- 每个ios开发者都应该知道Top 10 Swift三方库
- 每个ios开发者都应该知道Top 10 Swift三方库
- 每个ios开发者都应该知道Top 10 Swift三方库
- 每个ios开发者都应该知道Top 10 Swift三方库
- 每个android开发者都应该知道的Top 5三方库(2015版)
- 每个开发者都应该知道的 5 个设计技巧
- 每个开发者都应该知道的 5 个设计技巧
- 每个Android开发者都应该知道的开源库
- 每个Linux开发者都应该知道的一些知识
- 每个MySQL开发者都应该了解的10个技巧
- 每个 MySQL 开发者都应该了解的 10 个技巧
- vs2008快捷键使用 每个开发者都应该知道的提示和诀窍
- 每个开发者都应该知道的20个实用jQuery插件
- vs2008快捷键使用 每个开发者都应该知道的提示和诀窍
- 每个Web开发者都应该知道的关 URL编码的知识
- 每个 Web 开发者都应该知道的关于 URL 编码的知识
- mysql修改时区
- mabatis标签 choose (when, otherwise)
- CMUSphinx-在你开始之前2
- Atom之Markdown环境搭建
- OkHttp3的使用,代码奉上
- 每个ios开发者都应该知道Top 10 Swift三方库
- HDU 2102 A计划【BFS广搜】
- 运维日记004 - 关于开发和运维的点滴感悟
- STM8调试笔记
- 地球实时卫星图片资源-与当前时间只相差30分钟
- Javascript对cookie的“增删查改”
- 移动浪潮下,看地推吧如何“霸占”行业新风口
- opencv——hough变换
- CocoaPods安装教程