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
540
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
2.4k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
170
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.7k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.4k
Parser Combinators
yhkaplan
0
270
The Great Swift Migration
yhkaplan
1
4k
Speeding Up Your CI
yhkaplan
0
470
Automate All the Things
yhkaplan
4
2.4k
Other Decks in Programming
See All in Programming
状態と共に暮らす:ステートフルへの挑戦
ypresto
3
1.2k
最速Green Tea 🍵 Garbage Collector
kuro_kurorrr
1
120
七輪ライブラリー: Claude AI で作る Next.js アプリ
suneo3476
1
190
SwiftDataのカスタムデータストアを試してみた
1mash0
0
150
データと事例で振り返るDevin導入の"リアル" / The Realities of Devin Reflected in Data and Case Studies
rkaga
1
1k
カオスに立ち向かう小規模チームの装備の選択〜フルスタックTSという装備の強み _ 弱み〜/Choosing equipment for a small team facing chaos ~ Strengths and weaknesses of full-stack TS~
bitkey
1
140
エンジニア向けCursor勉強会 @ SmartHR
yukisnow1823
3
12k
VitestのIn-Source Testingが便利
taro28
8
2.4k
Designing Your Organization's Test Pyramid ( #scrumniigata )
teyamagu
PRO
5
1.4k
個人開発の学生アプリが企業譲渡されるまで
akidon0000
2
1.2k
データベースの技術選定を突き詰める ~複数事例から考える最適なデータベースの選び方~
nnaka2992
0
440
はじめてのPDFKit.pdf
shomakato
0
100
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
2.9k
Music & Morning Musume
bryan
47
6.5k
KATA
mclloyd
29
14k
The Pragmatic Product Professional
lauravandoore
33
6.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
33k
Documentation Writing (for coders)
carmenintech
71
4.8k
A better future with KSS
kneath
239
17k
Build The Right Thing And Hit Your Dates
maggiecrowley
35
2.7k
A Tale of Four Properties
chriscoyier
159
23k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.2k
Adopting Sorbet at Scale
ufuk
76
9.4k
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