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
550
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
社内での開発コミュニティ活動とモジュラーモノリス標準化事例のご紹介/xPalette and Introduction of Modular monolith standardization
m4maruyama
1
120
事業戦略を理解してソフトウェアを設計する
masuda220
PRO
22
6k
Cursor Meetup Tokyo ゲノミクスとCursor: 進化と制約のあいだ
koido
2
1k
業務自動化をJavaとSeleniumとAWS Lambdaで実現した方法
greenflagproject
1
110
Blueskyのプラグインを作ってみた
hakkadaikon
1
540
Parallel::Pipesの紹介
skaji
2
910
Create a website using Spatial Web
akkeylab
0
280
Perlで痩せる
yuukis
1
680
ReadMoreTextView
fornewid
1
390
「兵法」から見る質とスピード
ickx
0
270
コード書くの好きな人向けAIコーディング活用tips #orestudy
77web
3
300
インターフェース設計のコツとツボ
togishima
2
710
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.7k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
16
920
Designing for humans not robots
tammielis
253
25k
Why Our Code Smells
bkeepers
PRO
337
57k
Six Lessons from altMBA
skipperchong
28
3.8k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
650
Code Review Best Practice
trishagee
68
18k
How to Ace a Technical Interview
jacobian
276
23k
Making Projects Easy
brettharned
116
6.2k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
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