Download - Oss written in swift
![Page 1: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/1.jpg)
OSS written in Swift
yukiasai
![Page 2: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/2.jpg)
・浅井勇樹 28歳
・Github : yukiasai
・出身:福井県福井高専
・今 : 株式会社マネーフォワード
・マネーフォワード -自動家計簿アプリ
・過去 : 株式会社ナチュラルスタイル
・ZOZOTOWN -ファッション通販アプリ
・WEAR -ファッションコーディネートアプリ
・得意 : iOS
・趣味 : ディズニーランド
自己紹介
![Page 3: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/3.jpg)
日常のコードリーディング
・Trending repositories - Github
・最近人気のリポジトリランキング
・Search Github - Github
・使い方がわからないクラスがあったらとりあえず検索
・みんながどんな使い方をしているかわかる
![Page 4: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/4.jpg)
社内でコードリーディング
・週1でSwiftコードリーディング会を開催
・全社のiOSエンジニアに知見を共有するのが目的
・有名どころから自作まで様々
・Alamofire
・Bond
・ObjectMapper
・SwiftTask
・などなど、、、
![Page 5: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/5.jpg)
最近までOSSをリリースしようとは思わなかった
![Page 6: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/6.jpg)
弊社技術顧問の松田明さんに言われたこと
![Page 7: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/7.jpg)
「コミュニティに還元しよう」
![Page 8: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/8.jpg)
「ただ乗りイクナイ」
![Page 9: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/9.jpg)
紹介するOSS
・Shoyu - yukiasai/Shoyu
・UITableViewをもっと簡単に
・Gecco - yukiasai/Gecco
・ビューにスポットライトをあてたい
・Kaiseki - yukiasai/Kaiseki
・JSONのパースを自動で
![Page 10: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/10.jpg)
すみません半分iOS系です
![Page 11: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/11.jpg)
Shoyu
UITableViewをもっと簡単に
![Page 12: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/12.jpg)
UITableViewを普通に使うとこうなる
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 3
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0: return 5
case 1: return 3
default: fatalError()
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->
UITableViewCell {
switch (indexPath.section, indexPath.row) {
case (0, _):
let cell = tableView.dequeueReusableCellWithIdentifier("MemberCell") as! MemberTableViewCell
return cell
case (1, _):
let cell = tableView.dequeueReusableCellWithIdentifier("GroupCell") as! GroupTableViewCell
return cell
default:
fatalError()
}
}
![Page 13: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/13.jpg)
UITableViewあるある
・デリゲートメソッドがswitch文(if文)地獄になる
・ビューの見た目とコードの見た目が乖離している
・どのセクションにどのローが表示されているか追うのが大変
・switch文を一箇所いじるとほぼ全箇所に影響する
・バグの温床となる可能性が極めて高い
・カスタムセルを使う場合デリゲートメソッド内でいちいちキャストしてやる必要がある
![Page 14: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/14.jpg)
Shoyuだとこうなる
tableView.source = Source()
.createSection { section in
section.createRows(5) { (_, row: Row<MemberTableViewCell>) in
row.height = 52
row.configureCell = { cell, _ in }
row.didSelect = { _ in }
}
}
.createSection { section in
section.createRows(3) { (_, row: Row<GroupTableViewCell>) in
row.height = 52
row.configureCell = { cell, _ in }
row.didSelect = { _ in }
}
}
tableView.reloadData()
![Page 15: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/15.jpg)
Shoyuの利点
・switch文(if文)地獄から開放される
・ビューの見た目とコードの見た目が近い
・セクションの追加、ローの追加がとっても楽ちん
![Page 16: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/16.jpg)
Gecco
ビューにスポットライトをあてたい
![Page 17: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/17.jpg)
・こんなのできないの?とよく聞かれる
・円、長方形、角丸長方形をサポート
・ModalViewControllerで表示
・そうじゃなくてもいい
Kaisekiで使われているテクニック
![Page 18: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/18.jpg)
Kaiseki
JSONのパースを自動で
![Page 19: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/19.jpg)
Kaisekiを使うとこうなる
こんなオブジェクトを宣言
class Object: Entity {
// Basic
let int = Property<Int>()
let string = Property<String>()
// Array
let array = Property<[Bool]>()
// Optional
let optional = Property<Int?>()
// Entity
let object = Property<Object?>()
}
使い方let json: [String: AnyObject] = [“int”: 1, “string”: “aaa”, “array”: [true, false], “optional”: null, ....]
let obj = Object.fromJSON(json: jsonData)
obj.int.value // -> 1
obj.string.value // -> aaa
![Page 20: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/20.jpg)
Kaisekiで使われているテクニック
・Mirrorを用いた自動マッピング
・プロトコルで構造体(Int,Optional,Array)を拡張
![Page 21: Oss written in swift](https://reader034.vdocuments.mx/reader034/viewer/2022050614/58ad1fa31a28ab50728b5a43/html5/thumbnails/21.jpg)
Thank you!
yukiasai