Alamofire
Alamofire 是一款用Swift編寫(xiě)的HTTP 網(wǎng)絡(luò)庫(kù),類(lèi)似于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編寫(xiě)的一款用于加密的庫(kù),支持MD5 SHA1 SHA224 SHA256 SHA384 SHA512 SHA3 AES 等等,只用非常簡(jiǎn)單,支持iOS, macOS, AppleTV, watchOS, Linux 等平臺(tái)
SwiftyJSON
SwiftyJSON 讓在Swift里使用JSON數(shù)據(jù)變得非常容易
-
使用SwiftyJSON前后對(duì)比
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開(kāi)發(fā)的圖片加載庫(kù),現(xiàn)在是4.0版本,API方面相比之前有了挺大的改變,使用后感覺(jué)更為靈活了,對(duì)于學(xué)習(xí)Swift的思想有不錯(cuò)的學(xué)習(xí)價(jià)值。
let url = URL(string: "url_of_your_image") imageView.kf.setImage(with: url)
SnapKit
-
SnapKit SnapKit是Masonry團(tuán)隊(duì)開(kāi)發(fā)的Swift版本,對(duì)于習(xí)慣了使用Masonry開(kāi)發(fā)的開(kāi)發(fā)者來(lái)說(shuō)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 是一款簡(jiǎn)化iOS UIView動(dòng)畫(huà)的第三方庫(kù),即使蘋(píng)果在動(dòng)畫(huà)方面已經(jīng)支持的非常好,但是在一些連貫的動(dòng)畫(huà)實(shí)現(xiàn)方面還有不少的不方便的地方,Spring極大的方便了實(shí)現(xiàn)一些復(fù)雜的組合動(dòng)畫(huà)??磦€(gè)簡(jiǎn)單的例子
layer.y = -50 animateToNext { layer.animation = "fall" layer.animateTo() }
SwiftDate
<p align="center" >
</p>
- SwiftDate 項(xiàng)目開(kāi)發(fā)里總避免不了日期的格式化、計(jì)算、轉(zhuǎn)換、時(shí)間段等等,SwiftDate就是為了解決這些問(wèn)題的
-
可以簡(jiǎn)單的進(jìn)行日期操作! 例如:
aDate + 2.weeks + 1.hour or (1.year - 2.hours + 16.minutes).fromNow()
-
非常方便的從 timezone, locale and calendar 進(jìn)行轉(zhuǎn)換. 使用這個(gè)工具類(lèi)
DateInRegion
可以進(jìn)行日期的轉(zhuǎn)換! -
非常方便的進(jìn)行日期比較
<,>,==,<=,>=
. 例如, 你可以這么做aDate1 >= aDate2 or aDate1.isIn(anotherDate,.day)
-
非常簡(jiǎn)單的和日期組件. E.g.
aDateInRegion.day
orhour
,minutes
! -
其他一些簡(jiǎn)單的工具 (
isYesterday,isTomorrow,isBefore()
...)
IGListKit
- IGListKit 該庫(kù)是Instagram的公司用于開(kāi)發(fā)Instagram App使用的UI框架 是基于UICollectionView的一款數(shù)據(jù)驅(qū)動(dòng)的UI編寫(xiě)框架,數(shù)據(jù)驅(qū)動(dòng)也就是當(dāng)我們寫(xiě)好UI代碼后剩下的只需要關(guān)系數(shù)據(jù)的變化即可實(shí)現(xiàn)復(fù)雜的試圖邏輯。
Texture

Texture 其實(shí)就是 AsyncDisplayKit Texture的基本單元是node,ASDisplayNode是UIView之上的抽象層,同時(shí)也是CALayer的抽象層。和只能被用在主線程的視圖不同,nodes是線程安全的:你能并行的實(shí)例化并設(shè)置整個(gè)node層級(jí),并且在后臺(tái)線程里運(yùn)行。
-
用法和使用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 是一個(gè)高度抽象的網(wǎng)絡(luò)庫(kù),他的理念是讓你不用關(guān)心網(wǎng)絡(luò)請(qǐng)求的底層的實(shí)現(xiàn)細(xì)節(jié),只用定義你關(guān)心的業(yè)務(wù)。且Moya采用橋接和組合來(lái)進(jìn)行封裝(默認(rèn)橋接了Alamofire),使得Moya非常好擴(kuò)展,讓你不用修改Moya源碼就可以輕易定制。官方給出幾個(gè)Moya主要優(yōu)點(diǎn):
編譯時(shí)檢查API endpoint權(quán)限
讓你使用枚舉定義各種不同Target, endpoints
-
把stubs當(dāng)做一等公民對(duì)待,因此測(cè)試超級(jí)簡(jiǎn)單。
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 可以讓你在開(kāi)發(fā)種像安卓開(kāi)發(fā)那樣使用資源文件
R.image.settingsIcon()
,是不是比用Swift的方式要賞心悅目的很多,這樣做有很多好處,首先是避免了字符串拼寫(xiě)錯(cuò)誤導(dǎo)致的問(wèn)題太難被發(fā)現(xiàn)的問(wèn)題,還有R.Swift可以在編譯時(shí)檢查那些文件是沒(méi)有被用到的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 是一款實(shí)現(xiàn)轉(zhuǎn)場(chǎng)動(dòng)畫(huà)的庫(kù)
-
一個(gè)例子
HeroredView.heroID = "ironMan" blackView.heroID = "batMan" isHeroEnabled = true redView.heroID = "ironMan" blackView.heroID = "batMan" whiteView.heroModifiers = [.translate(y:100)]