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
510
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
2.2k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
150
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.6k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.3k
Parser Combinators
yhkaplan
0
240
The Great Swift Migration
yhkaplan
1
4k
Speeding Up Your CI
yhkaplan
0
440
Automate All the Things
yhkaplan
4
2.2k
Other Decks in Programming
See All in Programming
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
430
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
370
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
440
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
100
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Fireside Chat
paigeccino
34
3.1k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Code Review Best Practice
trishagee
65
17k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Music & Morning Musume
bryan
46
6.2k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
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