Alamofire
Alamofire 是一款用Swift編寫的HTTP 網絡庫,類似于OC里的AFNetWorking
-
使用舉例
Alamofire.request("https://httpbin.org/get").responseJSON { response in print("Request: \(String(describing: response.request))") // original url request print("Response: \(String(describing: response.response))") // http url response print("Result: \(response.result)") // response serialization result if let json = response.result.value { print("JSON: \(json)") // serialized json response } if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) { print("Data: \(utf8Text)") // original server data as UTF8 string } }
CryptoSwift
- CryptoSwift 是使用Swift編寫的一款用于加密的庫,支持MD5 SHA1 SHA224 SHA256 SHA384 SHA512 SHA3 AES 等等,只用非常簡單,支持iOS, macOS, AppleTV, watchOS, Linux 等平臺
SwiftyJSON
SwiftyJSON 讓在Swift里使用JSON數據變得非常容易
-
使用SwiftyJSON前后對比
if let statusesArray = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: Any]], let user = statusesArray[0]["user"] as? [String: Any], let username = user["name"] as? String { // Finally we got the username }
let json = JSON(data: dataFromNetworking) if let userName = json[0]["user"]["name"].string { //Now you got your value }
一切都變得異常美好
Kingfisher
-
Kingfisher 是一款輕量、純Swift開發的圖片加載庫,現在是4.0版本,API方面相比之前有了挺大的改變,使用后感覺更為靈活了,對于學習Swift的思想有不錯的學習價值。
let url = URL(string: "url_of_your_image") imageView.kf.setImage(with: url)
SnapKit
-
SnapKit SnapKit是Masonry團隊開發的Swift版本,對于習慣了使用Masonry開發的開發者來說SnapKit非常容易上手。
import SnapKit class MyViewController: UIViewController { lazy var box = UIView() override func viewDidLoad() { super.viewDidLoad() self.view.addSubview(box) box.snp.makeConstraints { (make) -> Void in make.width.height.equalTo(50) make.center.equalTo(self.view) } } }
Spring
-
Spring 是一款簡化iOS UIView動畫的第三方庫,即使蘋果在動畫方面已經支持的非常好,但是在一些連貫的動畫實現方面還有不少的不方便的地方,Spring極大的方便了實現一些復雜的組合動畫??磦€簡單的例子
layer.y = -50 animateToNext { layer.animation = "fall" layer.animateTo() }
SwiftDate
<p align="center" >
</p>
- SwiftDate 項目開發里總避免不了日期的格式化、計算、轉換、時間段等等,SwiftDate就是為了解決這些問題的
-
可以簡單的進行日期操作! 例如:
aDate + 2.weeks + 1.hour or (1.year - 2.hours + 16.minutes).fromNow()
-
非常方便的從 timezone, locale and calendar 進行轉換. 使用這個工具類
DateInRegion
可以進行日期的轉換! -
非常方便的進行日期比較
<,>,==,<=,>=
. 例如, 你可以這么做aDate1 >= aDate2 or aDate1.isIn(anotherDate,.day)
-
非常簡單的和日期組件. E.g.
aDateInRegion.day
orhour
,minutes
! -
其他一些簡單的工具 (
isYesterday,isTomorrow,isBefore()
...)
IGListKit
- IGListKit 該庫是Instagram的公司用于開發Instagram App使用的UI框架 是基于UICollectionView的一款數據驅動的UI編寫框架,數據驅動也就是當我們寫好UI代碼后剩下的只需要關系數據的變化即可實現復雜的試圖邏輯。
Texture

Texture 其實就是 AsyncDisplayKit Texture的基本單元是node,ASDisplayNode是UIView之上的抽象層,同時也是CALayer的抽象層。和只能被用在主線程的視圖不同,nodes是線程安全的:你能并行的實例化并設置整個node層級,并且在后臺線程里運行。
-
用法和使用UIKit的組件用法差不多
_imageView = [[UIImageView alloc] init]; _imageView.image = [UIImage imageNamed:@"hello"]; _imageView.frame = CGRectMake(10.0f, 10.0f, 40.0f, 40.0f); [self.view addSubview:_imageView];
_imageNode = [[ASImageNode alloc] init]; _imageNode.backgroundColor = [UIColor lightGrayColor]; _imageNode.image = [UIImage imageNamed:@"hello"]; _imageNode.frame = CGRectMake(10.0f, 10.0f, 40.0f, 40.0f); [self.view addSubview:_imageNode.view];
Moya
Moya 是一個高度抽象的網絡庫,他的理念是讓你不用關心網絡請求的底層的實現細節,只用定義你關心的業務。且Moya采用橋接和組合來進行封裝(默認橋接了Alamofire),使得Moya非常好擴展,讓你不用修改Moya源碼就可以輕易定制。官方給出幾個Moya主要優點:
編譯時檢查API endpoint權限
讓你使用枚舉定義各種不同Target, endpoints
-
把stubs當做一等公民對待,因此測試超級簡單。
provider = MoyaProvider<GitHub>() provider.request(.zen) { result in switch result { case let .success(moyaResponse): let data = moyaResponse.data let statusCode = moyaResponse.statusCode // do something with the response data or statusCode case let .failure(error): // this means there was a network failure - either the request // wasn't sent (connectivity), or no response was received (server // timed out). If the server responds with a 4xx or 5xx error, that // will be sent as a ".success"-ful response. } }
R.swift
-
R.swift 可以讓你在開發種像安卓開發那樣使用資源文件
R.image.settingsIcon()
,是不是比用Swift的方式要賞心悅目的很多,這樣做有很多好處,首先是避免了字符串拼寫錯誤導致的問題太難被發現的問題,還有R.Swift可以在編譯時檢查那些文件是沒有被用到的let icon = UIImage(named: "settings-icon") let font = UIFont(name: "San Francisco", size: 42) let viewController = CustomViewController(nibName: "CustomView", bundle: nil) let string = String(format: NSLocalizedString("welcome.withName", comment: ""), locale: NSLocale.current, "Arthur Dent")
let icon = R.image.settingsIcon() let font = R.font.sanFrancisco(size: 42) let viewController = CustomViewController(nib: R.nib.customView) let string = R.string.localizable.welcomeWithName("Arthur Dent")
Hero
- Hero
- Hero
- Hero
Hero 是一款實現轉場動畫的庫
-
一個例子
HeroredView.heroID = "ironMan" blackView.heroID = "batMan" isHeroEnabled = true redView.heroID = "ironMan" blackView.heroID = "batMan" whiteView.heroModifiers = [.translate(y:100)]