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
620
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Property Wrappers
yhkaplan
January 21, 2020
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
3.5k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
210
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.9k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.9k
Parser Combinators
yhkaplan
0
320
The Great Swift Migration
yhkaplan
1
4.3k
Speeding Up Your CI
yhkaplan
0
520
Automate All the Things
yhkaplan
4
2.7k
Other Decks in Programming
See All in Programming
Android CLI
fornewid
0
240
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
400
Hono + Inertia + React で LP を構築した話
oukayuka
2
170
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
280
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
180
AIの中の人になってみる
htkym
0
120
リアルな遅延を測る仕様
kota_yata
1
130
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
110
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1.2k
Go 1.27 における memory allocation の高速化
andpad
0
320
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
240
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
110
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
A Soul's Torment
seathinner
6
3.5k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Embracing the Ebb and Flow
colly
88
5.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.1k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.5k
A better future with KSS
kneath
240
18k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
440
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
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