Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Property Wrappers
yhkaplan
January 21, 2020
Programming
0
260
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
890
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
72
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.1k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
2.1k
Parser Combinators
yhkaplan
0
180
The Great Swift Migration
yhkaplan
1
2.9k
Speeding Up Your CI
yhkaplan
0
270
Automate All the Things
yhkaplan
4
1.7k
Other Decks in Programming
See All in Programming
More Than Micro Frontends: 3 Further Use Cases for Module Federation @DWX 2022
manfredsteyer
PRO
0
110
GoogleI/O2022 LT報告会資料
shinsukefujita1126
0
410
Managing Error Messages with your Oracle Database REST APIs
thatjeffsmith
0
160
Amazon ECSのネットワーク関連コストの話
msato
0
670
JSのウェブフレームワークで高速なルーターを実装する方法
usualoma
1
1.9k
"What's new in Swift"の要約 / swift_5_7_summary
uhooi
1
350
設計の学び方:自分流のススメ
masuda220
PRO
10
7.5k
パターンマッチングを学んで新しいJavaの世界へ!Java 18までの目玉機能をおさらいしよう / Java 18 pattern matching
ihcomega56
3
450
React Nativeアプリを DDDで開発している話
nihemak
0
160
模組化的Swift架構(二) DDD速成
haifengkao
0
390
Jetpack Composeでの画面遷移
iwata_n
0
200
プロダクトのタイプ別 GraphQL クライアントの選び方
shozawa
0
5.8k
Featured
See All Featured
Embracing the Ebb and Flow
colly
73
3.4k
Designing the Hi-DPI Web
ddemaree
272
32k
We Have a Design System, Now What?
morganepeng
35
3k
The Pragmatic Product Professional
lauravandoore
19
3k
4 Signs Your Business is Dying
shpigford
169
20k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
237
19k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
224
49k
Fontdeck: Realign not Redesign
paulrobertlloyd
73
4.1k
jQuery: Nuts, Bolts and Bling
dougneiner
56
6.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
316
22k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
10
3.5k
The World Runs on Bad Software
bkeepers
PRO
57
5.3k
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