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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
yhkaplan
January 21, 2020
Programming
620
0
Share
Property Wrappers
yhkaplan
January 21, 2020
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
3.3k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
210
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.9k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.9k
Parser Combinators
yhkaplan
0
310
The Great Swift Migration
yhkaplan
1
4.2k
Speeding Up Your CI
yhkaplan
0
510
Automate All the Things
yhkaplan
4
2.6k
Other Decks in Programming
See All in Programming
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
330
OCRを使ってゲームのアイテムをデータ化する
kishikawakatsumi
0
130
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
2.2k
inferと仲良くなる10分間
ryokatsuse
1
360
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
17
5.6k
AIエージェントと協働するCLI開発 — BunとOpenClawで学んだこと
yoshikouki
1
230
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
310
The NotImplementedError Problem in Ruby
koic
0
280
Modding RubyKaigi for Myself
yui_knk
0
870
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
340
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.5k
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2k
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
220
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
820
Building an army of robots
kneath
306
46k
The Invisible Side of Design
smashingmag
302
52k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
300
How to Ace a Technical Interview
jacobian
281
24k
Test your architecture with Archunit
thirion
1
2.3k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
200
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