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
530
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
2.3k
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.4k
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
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
120
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
550
Conform を推す - Advocating for Conform
mizoguchicoji
3
680
ASP. NET CoreにおけるWebAPIの最新情報
tomokusaba
0
360
JavaScriptツール群「UnJS」を5分で一気に駆け巡る!
k1tikurisu
10
1.8k
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
110
SpringBoot3.4の構造化ログ #kanjava
irof
2
970
CloudNativePGがCNCF Sandboxプロジェクトになったぞ! 〜CloudNativePGの仕組みの紹介〜
nnaka2992
0
220
Grafana Cloudとソラカメ
devoc
0
140
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
170
TokyoR116_BeginnersSession1_環境構築
kotatyamtema
0
110
Compose でデザインと実装の差異を減らすための取り組み
oidy
1
300
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Done Done
chrislema
182
16k
Docker and Python
trallard
44
3.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
12
950
Practical Orchestrator
shlominoach
186
10k
Producing Creativity
orderedlist
PRO
343
39k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Automating Front-end Workflow
addyosmani
1367
200k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Adopting Sorbet at Scale
ufuk
74
9.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
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