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
420
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
1.8k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
120
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.5k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3k
Parser Combinators
yhkaplan
0
230
The Great Swift Migration
yhkaplan
1
3.7k
Speeding Up Your CI
yhkaplan
0
370
Automate All the Things
yhkaplan
4
2k
Other Decks in Programming
See All in Programming
Hanami and htmx
bkuhlmann
0
200
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
6
870
Ruby Function Composition
bkuhlmann
1
330
0→1と1→10の狭間で Javaという技術選定を振り返る/Reflecting on the Decision to Choose Java Between Scaling from 0 to 1 and 1 to 10
jaguar_imo
2
380
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
160
Blue/Greenデプロイの導入による 運用フローの改善
kudoas
1
360
チーム力を高めるスクラム実践法:カンバン公開と課題攻略について - ニフティのスクラムトーク Vol. 2 - NIFTY Tech Talk #18
niftycorp
PRO
1
110
Goのmultiple errorsについて (2024年4月版)
syumai
1
240
Front-end application development, Symfony-style(s)
dunglas
2
1.9k
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
160
Netty Chicago Java User Group 2024-04-17
sullis
0
170
Ruby GitHub Packages
bkuhlmann
0
630
Featured
See All Featured
Building Effective Engineering Teams - LeadDev
addyosmani
27
1.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
No one is an island. Learnings from fostering a developers community.
thoeni
14
2.1k
RailsConf 2023
tenderlove
2
530
Product Roadmaps are Hard
iamctodd
43
9.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
20
1.6k
For a Future-Friendly Web
brad_frost
171
8.9k
The Cult of Friendly URLs
andyhume
74
5.7k
Web development in the modern age
philhawksworth
202
10k
The Cost Of JavaScript in 2023
addyosmani
14
3.8k
Faster Mobile Websites
deanohume
297
30k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
220
21k
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