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.5k
Parser Combinators
yhkaplan
0
270
The Great Swift Migration
yhkaplan
1
4.1k
Speeding Up Your CI
yhkaplan
0
480
Automate All the Things
yhkaplan
4
2.4k
Other Decks in Programming
See All in Programming
💎 My RubyKaigi Effect in 2025: Top Ruby Companies 🌐
yasulab
PRO
1
130
UPDATEがシステムを複雑にする? イミュータブルデータモデルのすすめ
shimomura
0
210
複数アプリケーションを育てていくための共通化戦略
irof
2
620
Use Perl as Better Shell Script
karupanerura
0
660
Devinで実践する!AIエージェントと協働する開発組織の作り方
masahiro_nishimi
6
2.6k
MLOps Japan 勉強会 #52 - 特徴量を言語を越えて一貫して管理する, 『特徴量ドリブン』な MLOps の実現への試み
taniiicom
2
570
推論された型の移植性エラーTS2742に挑む
teamlab
PRO
0
150
TypeScript を活かしてデザインシステム MCP を作る / #tskaigi_after_night
izumin5210
4
480
External SecretsのさくらProvider初期実装を担当しています
logica0419
0
240
當開發遇上包裝:AI 如何讓產品從想法變成商品
clonn
0
2.6k
ts-morph実践:型を利用するcodemodのテクニック
ypresto
1
540
Cursor Meetup Tokyo ゲノミクスとCursor: 進化と制約のあいだ
koido
1
290
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
180
53k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
14
1.5k
Embracing the Ebb and Flow
colly
85
4.7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Side Projects
sachag
454
42k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Art, The Web, and Tiny UX
lynnandtonic
298
21k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.6k
Balancing Empowerment & Direction
lara
1
87
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