Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Property Wrappers
Search
yhkaplan
January 21, 2020
Programming
0
520
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
2.2k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
160
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.6k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.3k
Parser Combinators
yhkaplan
0
250
The Great Swift Migration
yhkaplan
1
4k
Speeding Up Your CI
yhkaplan
0
450
Automate All the Things
yhkaplan
4
2.3k
Other Decks in Programming
See All in Programming
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
1.9k
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
170
BEエンジニアがFEの業務をできるようになるまでにやったこと
yoshida_ryushin
0
200
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
390
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
300
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
570
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
290
ゼロからの、レトロゲームエンジンの作り方
tokujiros
3
1.1k
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
940
선언형 UI에서의 상태관리
l2hyunwoo
0
270
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
190
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
113
50k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.6k
KATA
mclloyd
29
14k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Practical Orchestrator
shlominoach
186
10k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
Optimising Largest Contentful Paint
csswizardry
33
3k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7.1k
Transcript
Property Wrappers 1
What are they? 2
→ New in 5.1 → Java-like annotations → Can accept
(generic) parameters → Used in SwiftUI 3
Purpose 4
Examples 5
SwiftUI 6
struct ContentView: View { @State private var value = 0.0
var body: some View { VStack { Text("Value is \(value)") Slider(value: $value) } } } 7
UIKit/ Foundation 8
class ViewController: UIViewController { @Keychain(key: "secret_info") var secretInfo = ""
} 9
Let's make one! 10
@propertyWrapper struct TwelveOrLess { private var number = 0 var
wrappedValue: Int { get { return number } set { number = min(newValue, 12) } } } // Use struct S { @TwelveOrLess var num = 13 // 12 } 11
@propertyWrapper struct Clamped { private var number = 0 private
let maxNum: Int private let minNum: Int var wrappedValue: Int { get { return number } set { number = max(min(newValue, maxNum), minNum) } } } // Use struct S { @Clamped(maxNum: 10, minNum: 0) var num = 13 // 10 } 12
Projected values 13
@propertyWrapper struct State<T> { //... var projectedValue: Binding<T> } 14
struct ContentView: View { @State private var isDisabled = false
var body: some View { OtherView($isDisabled) // Binding<Bool> } } 15
Conclusion 16
More info 17
→ The Swift Programming Language → Burritos 18