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
460
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
2k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
140
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.5k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.1k
Parser Combinators
yhkaplan
0
230
The Great Swift Migration
yhkaplan
1
3.8k
Speeding Up Your CI
yhkaplan
0
400
Automate All the Things
yhkaplan
4
2.1k
Other Decks in Programming
See All in Programming
AWS初心者ってどうやってAWSを学ぶ?〜アプリエンジニアがやってよかったアーキテクチャ学習方法〜
yamanashi_ren01
0
190
なぜ宣言的 UI は壊れにくいのか / Why declarative UI is less fragile
uenitty
29
13k
最近追加した型の紹介とその振り返り
aki19035vc
0
180
企業向け生成AIアプリの 開発から得られた知見
takaakikakei
0
310
スクラムマスターって孤独じゃないですか?
yoshitaroyoyo
1
140
Advanced App Shrinking Techniques
cbeyls
2
150
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
日付と正規化
megmogmog1965
0
140
Product Management LT会_クアンド新家
shinshin
0
260
最古の関数型言語「Lisp」ことはじめ / lisp_in_kamiyama
uhooi
1
190
12年前の『型システム入門』翻訳の思い出話
mame
11
1.2k
Harnessing Large Language Models for Training-free Video Anomaly Detection
tereka114
1
1.3k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
166
14k
Practical Orchestrator
shlominoach
185
10k
Automating Front-end Workflow
addyosmani
1362
200k
Visualization
eitanlees
139
14k
Docker and Python
trallard
37
2.9k
Fontdeck: Realign not Redesign
paulrobertlloyd
79
5.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.3k
RailsConf 2023
tenderlove
16
720
Design by the Numbers
sachag
277
18k
The MySQL Ecosystem @ GitHub 2015
samlambert
248
12k
Producing Creativity
orderedlist
PRO
340
39k
Debugging Ruby Performance
tmm1
71
11k
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