$30 off During Our Annual Pro Sale. View Details »
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.8k
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
500
Automate All the Things
yhkaplan
4
2.5k
Other Decks in Programming
See All in Programming
手軽に積ん読を増やすには?/読みたい本と付き合うには?
o0h
PRO
1
160
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.4k
connect-python: convenient protobuf RPC for Python
anuraaga
0
370
WebRTC と Rust と8K 60fps
tnoho
2
1.9k
20 years of Symfony, what's next?
fabpot
2
320
MAP, Jigsaw, Code Golf 振り返り会 by 関東Kaggler会|Jigsaw 15th Solution
hasibirok0
0
220
俺流レスポンシブコーディング 2025
tak_dcxi
13
8.2k
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
3
780
TypeScript 5.9 で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
1.2k
認証・認可の基本を学ぼう前編
kouyuume
0
180
Developing static sites with Ruby
okuramasafumi
0
190
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
320
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Navigating Team Friction
lara
191
16k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.3k
Typedesign – Prime Four
hannesfritz
42
2.9k
Music & Morning Musume
bryan
46
7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
How to train your dragon (web standard)
notwaldorf
97
6.4k
The Pragmatic Product Professional
lauravandoore
37
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