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
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
270
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
510
Go の GC の不得意な部分を克服したい
taiyow
3
1k
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
210
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
270
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
400
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
180
rails newと同時に型を書く
aki19035vc
5
680
為你自己學 Python
eddie
0
510
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
220
선언형 UI에서의 상태관리
l2hyunwoo
0
260
快速入門可觀測性
blueswen
0
490
Featured
See All Featured
Unsuck your backbone
ammeep
669
57k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Fireside Chat
paigeccino
34
3.1k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
490
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
GraphQLとの向き合い方2022年版
quramy
44
13k
Typedesign – Prime Four
hannesfritz
40
2.5k
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