Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Farewell SnapKit
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
kameike
July 26, 2018
Programming
1.9k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Farewell SnapKit
ありがとう!!!!さようなら!(?)
kameike
July 26, 2018
More Decks by kameike
See All by kameike
LeanScrum
kameike
3
1.3k
橋の下で安心して寝るための 『iOSアプリ設計パターン入門』
kameike
0
2.2k
サポートを求めてAppleに電話するまでの道のり
kameike
4
2.4k
header-comment
kameike
5
1.6k
Other Decks in Programming
See All in Programming
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.2k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
420
The Rails Doctrine Decade
koic
2
470
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
440
phperだってパンチカードでコーディングしたい
o0h
PRO
0
180
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
140
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
390
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
340
すこし踏み込む CancellationToken
htkym
2
1.6k
Agents on Rails - Rails at Scale 2026
irinanazarova
0
330
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
710
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
270
Crafting Experiences
bethany
1
370
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.1k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
390
Docker and Python
trallard
47
4.2k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
600
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Site-Speed That Sticks
csswizardry
13
1.5k
Transcript
Farewell SnapKit さようなら、ありがとうSnapkit! pixiv Inc. kameike 亀田 彗 2018.6.5
- パルシィというアプリを書いているもの です - 10月に福岡から上京 2 だれ @kameike
宣伝
• SnapKitよりもAnchorがDXが良いと思うよという話 • 最近わりと pod SnapKitを見かけたので... • 13,000スターのスーパースター。ありがとうの気持ち、大切! 4 今日の話の要約
5 前提
6 AutoLayout(viewに制約を追加するやつ) をコードで作りたい!
let constraints = NSLayoutConstraint( item: subview, attribute: .left, relatedBy: .equal,
toItem: view, attribute: .left, multiplier: 1.0, constant: 0.0) 普通に作る 10
let constraints = NSLayoutConstraint.constraints( withVisualFormat: "H:|-15-[view]-15-|", metrics: nil, views: ["view":
subView]) 例のアレ(VisualFormatLanguage) 10
10
10
// SnapKit subview.snp.makeConstraints { constraintMaker in constraintMaker.top.equalTo(view) constraintMaker.bottom.equalTo(view) constraintMaker.left.equalTo(view) constraintMaker.right.equalTo(view)
} SnapKit 10
// Anchor NSLayoutConstraint.activate([ subview.topAnchor.constraint(equalTo: view.topAnchor), subview.bottomAnchor.constraint(equalTo: view.bottomAnchor), subview.trailingAnchor.constraint(equalTo: view.trailingAnchor), subview.leadingAnchor.constraint(equalTo:
view.leadingAnchor) ]) Anchor(iOS9~) 10
13 書き方こそ似ているけども、 Anchorの方がDXが良いぞ〜! (あとUIKitだし...寿命も長いはず...)
14 Anchorのよさ
// SnapKit subview.snp.makeConstraints { constraintMaker in constraintMaker.top.equalTo(_ other: ConstraintRelatableTarget) }
// ConstraintRelatableTargetとして使える型 // Int UInt Float Double CGFloat CGSize CGPoint // UIEdgeInsets, UIView SnapKit 10
16 暗黙的...
SnapKit 10
// Anchor subview.topAnchor.constraint(_ equalTo: NSLayoutAnchor<NSLayoutYAxisAnchor>) Anchor 10
Anchor 10
20 よさ2 ありえない組み合わせが 型によって排除されている
// SnapKit subview.top.equalTo(superView.snp.right) このようなコード 10
期待される挙動 10
23 実行時エラー:sob:
// Anchor view.topAnchor.constraint(equalTo: superView.leadingAnchor) Anchorだと...! 10
// Anchor view.topAnchor.constraint(equalTo: superView.leadingAnchor) このようなコード 10 NSLayoutXAxisAnchor
26 コンパイルエラーになる:joy:
// SnapKit subview.top.bottom.equalTo(view).offset(10).offset(20) ちなみにSnapKitはこんなコードを コンパイルできてしまう 10
28 Anchor便利...!
29 SnapKit->Anchorで 移行Tips
30 基本的にはすんなり行くはず!
// SnapKit let offset = UIEdgeInsets(top: 10, left: 10, bottom:
10, right: 10) make.edges.equalTo(view).offset(offset) Edgeがほしい! 10
extension UIView { func edges(equalTo view: UIView, offset: UIEdgeInsets =
UIEdgeInsets()) { NSLayoutConstraint.activate([ topAnchor.constraint(equalTo: view.topAnchor, constant: offset.top), bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -offset.bottom), leftAnchor.constraint(equalTo: view.leftAnchor, constant: offset.left), rightAnchor.constraint(equalTo: view.rightAnchor, constant: -offset.right) ]) } } extensionでなんとかなる!10行ぐらい! 10
// SnapKit view.edges.equalTo(view).offset(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
// Anchor+Extension view.edges(equalTo: view, offset: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)) なんとかなった...! 10
// leading, trailing extension UIView { func edges(equalTo view: UIView,
offset: NSDirectionalEdgeInset) { NSLayoutConstraint.activate([ topAnchor.constraint(equalTo: view.topAnchor, constant: offset.top), bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -offset.bottom), leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: offset.leadingAnchor), trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -offset.trailingAnchor) ]) } } 余談 leading trailingを使いたいなら 10
let offset = 3 * 5 // SnapKit だと大丈夫だけど make.top.equalTo(view).offset(offset)
// Anchor だとコンパイルエラー subview.topAnchor.constraint(equalTo: view.topAnchor, constant: offset) ConstraintXXXTarget的なものを CGFloatにする必要がある 10
36 余談の余談
@available(iOS 6.0, *) open func addConstraint(_ constraint: NSLayoutConstraint) // This
method will be deprecated in a future release and should be avoided. // Instead, set NSLayoutConstraint's active property to YES. 10 addConstraintは 使わない方がいい
let constraint = view.bottomAnchor.constraint(equalTo: bottomAnchor) constraint.isActive = true // もしくは
NSLayoutConstraint.activate([constraint]) // でconstraintを有効に...! こういう感じで 10
39 SnapKit余談
• 7/17にSwift4対応!(そろそろ保守されなくなってきてるって言おうとおもっていたのに) • ので、まだ慌てる時間じゃない...!? 40 まだしっかり保守されている...!
• 3000行の本体コード(RxCocoaの1/3ぐらいコードがある...!) • 大体全ての型にMapperを書いてDSL上では独自型だけで表現できる世界を実現してい る(その分よしなであり、上述の問題もあり ...) 41 整ったコード(整いすぎでは...?!)
42 Priorityに若干のカスタマイズ public static var medium: ConstraintPriority { #if os(OSX)
return 501.0 #else return 500.0 #endif }
• 時々example作ったからマージしてよ!という PRがきていた • 苦労をかんじる最適化 43 13000スターつくと何が起こるか
• SnapKit→Anchor • ありがとうSnapKit!さようなら!(?) 44 まとめ