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
ぽちぽち選択するだけでOSSを読めるVSCode拡張機能
ymbigo
14
6.3k
VitestのIn-Source Testingが便利
taro28
9
2.4k
プロダクトエンジニアのしごと 〜 受託 × 高難度を乗り越えるOptium開発 〜
algoartis
0
220
「理解」を重視したAI活用開発
fast_doctor
0
300
2025-04-25 GitHub Copilot Agent ライブデモ(スクリプト)
goataka
0
110
知識0からカンファレンスやってみたらこうなった!
syossan27
5
240
API for docs
soutaro
4
1.7k
プロフェッショナルとしての成長「問題の深掘り」が導く真のスキルアップ / issue-analysis-and-skill-up
minodriven
8
2k
GitHub Copilot for Azureを使い倒したい
ymd65536
1
330
Ruby で作る RISC-V CPU エミュレーター / RISC-V CPU emulator made with Ruby
hayaokimura
5
1.1k
七輪ライブラリー: Claude AI で作る Next.js アプリ
suneo3476
1
190
Instrumentsを使用した アプリのパフォーマンス向上方法
hinakko
0
250
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Agile that works and the tools we love
rasmusluckow
329
21k
Building Applications with DynamoDB
mza
94
6.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2k
Into the Great Unknown - MozCon
thekraken
38
1.8k
Raft: Consensus for Rubyists
vanstee
137
6.9k
Optimising Largest Contentful Paint
csswizardry
37
3.2k
How GitHub (no longer) Works
holman
314
140k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
2.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Designing Experiences People Love
moore
142
24k
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