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
570
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
2.7k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
190
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.8k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.6k
Parser Combinators
yhkaplan
0
290
The Great Swift Migration
yhkaplan
1
4.1k
Speeding Up Your CI
yhkaplan
0
490
Automate All the Things
yhkaplan
4
2.4k
Other Decks in Programming
See All in Programming
Reactive Thinking with Signals and the Resource API
manfredsteyer
PRO
0
120
ドメイン駆動設計のエッセンス
masuda220
PRO
15
7.2k
TransformerからMCPまで(現代AIを理解するための羅針盤)
mickey_kubo
7
5.9k
AsyncSequenceとAsyncStreamのプロポーザルを全部読む!!
s_shimotori
1
220
KoogではじめるAIエージェント開発
hiroaki404
1
260
GC25 Recap: The Code You Reviewed is Not the Code You Built / #newt_gophercon_tour
mazrean
0
140
CSC509 Lecture 07
javiergs
PRO
0
250
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
1k
ビルドプロセスをデバッグしよう!
yt8492
0
200
Towards Transactional Buffering of CDC Events @ Flink Forward 2025 Barcelona Spain
hpgrahsl
0
120
HTTPじゃ遅すぎる! SwitchBotを自作ハブで動かして学ぶBLE通信
occhi
0
110
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
200
Featured
See All Featured
Gamification - CAS2011
davidbonilla
81
5.5k
Agile that works and the tools we love
rasmusluckow
331
21k
KATA
mclloyd
PRO
32
15k
What's in a price? How to price your products and services
michaelherold
246
12k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
2.9k
Code Review Best Practice
trishagee
72
19k
The Cult of Friendly URLs
andyhume
79
6.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
4 Signs Your Business is Dying
shpigford
186
22k
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