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
510
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
150
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.6k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.3k
Parser Combinators
yhkaplan
0
240
The Great Swift Migration
yhkaplan
1
3.9k
Speeding Up Your CI
yhkaplan
0
430
Automate All the Things
yhkaplan
4
2.2k
Other Decks in Programming
See All in Programming
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Jakarta EE meets AI
ivargrimstad
0
220
距離関数を極める! / SESSIONS 2024
gam0022
0
290
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
Better Code Design in PHP
afilina
PRO
0
130
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
CSC509 Lecture 11
javiergs
PRO
0
180
Featured
See All Featured
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
We Have a Design System, Now What?
morganepeng
50
7.2k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Code Reviewing Like a Champion
maltzj
520
39k
The Cult of Friendly URLs
andyhume
78
6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Testing 201, or: Great Expectations
jmmastey
38
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