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.6k
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
450
Automate All the Things
yhkaplan
4
2.3k
Other Decks in Programming
See All in Programming
Formの複雑さに立ち向かう
bmthd
1
720
ASP. NET CoreにおけるWebAPIの最新情報
tomokusaba
0
360
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
490
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
7
2.5k
Rails アプリ地図考 Flush Cut
makicamel
1
110
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
11
1.8k
『品質』という言葉が嫌いな理由
korimu
0
160
WebDriver BiDiとは何なのか
yotahada3
1
140
CNCF Project の作者が考えている OSS の運営
utam0k
5
690
CloudNativePGがCNCF Sandboxプロジェクトになったぞ! 〜CloudNativePGの仕組みの紹介〜
nnaka2992
0
220
チームリードになって変わったこと
isaka1022
0
190
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
660
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Mobile First: as difficult as doing things right
swwweet
223
9.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Embracing the Ebb and Flow
colly
84
4.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building an army of robots
kneath
302
45k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.8k
Producing Creativity
orderedlist
PRO
343
39k
For a Future-Friendly Web
brad_frost
176
9.5k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
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