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
530
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
2.3k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
160
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.7k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.4k
Parser Combinators
yhkaplan
0
250
The Great Swift Migration
yhkaplan
1
4k
Speeding Up Your CI
yhkaplan
0
460
Automate All the Things
yhkaplan
4
2.3k
Other Decks in Programming
See All in Programming
技術を改善し続ける
gumioji
0
180
From the Wild into the Clouds - Laravel Meetup Talk
neverything
0
180
ML.NETで始める機械学習
ymd65536
0
240
Visual StudioのGitHub Copilotでいろいろやってみる
tomokusaba
1
220
Generating OpenAPI schema from serializers throughout the Rails stack - Kyobashi.rb #5
envek
1
420
Lambdaの監視、できてますか?Datadogを用いてLambdaを見守ろう
nealle
2
730
未経験でSRE、はじめました! 組織を支える役割と軌跡
curekoshimizu
1
200
CDK開発におけるコーディング規約の運用
yamanashi_ren01
2
260
color-scheme: light dark; を完全に理解する
uhyo
7
500
もう僕は OpenAPI を書きたくない
sgash708
6
1.9k
Better Code Design in PHP
afilina
0
180
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
14
4.8k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
172
14k
A Modern Web Designer's Workflow
chriscoyier
693
190k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
134
33k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Producing Creativity
orderedlist
PRO
344
40k
Building an army of robots
kneath
303
45k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
100
18k
Writing Fast Ruby
sferik
628
61k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.2k
Typedesign – Prime Four
hannesfritz
41
2.5k
Practical Orchestrator
shlominoach
186
10k
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