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
560
Property Wrappers
yhkaplan
January 21, 2020
Tweet
Share
More Decks by yhkaplan
See All by yhkaplan
Using the latest UICollectionView APIs
yhkaplan
0
2.6k
Swift and Concurrency: The Plan for World Domination
yhkaplan
0
180
Backend-Driven UI: Making Screens Dynamic
yhkaplan
1
1.7k
Migrating from UIKit to SwiftUI efficiently
yhkaplan
4
3.6k
Parser Combinators
yhkaplan
0
280
The Great Swift Migration
yhkaplan
1
4.1k
Speeding Up Your CI
yhkaplan
0
490
Automate All the Things
yhkaplan
4
2.4k
Other Decks in Programming
See All in Programming
RDoc meets YARD
okuramasafumi
4
160
オープンセミナー2025@広島LT技術ブログを続けるには
satoshi256kbyte
0
160
旅行プランAIエージェント開発の裏側
ippo012
2
840
Zendeskのチケットを Amazon Bedrockで 解析した
ryokosuge
3
270
時間軸から考えるTerraformを使う理由と留意点
fufuhu
13
4.1k
Improving my own Ruby thereafter
sisshiki1969
1
150
フロントエンドのmonorepo化と責務分離のリアーキテクト
kajitack
2
160
Design Foundational Data Engineering Observability
sucitw
3
160
CloudflareのChat Agent Starter Kitで簡単!AIチャットボット構築
syumai
2
400
Claude Codeで挑むOSSコントリビュート
eycjur
0
190
サーバーサイドのビルド時間87倍高速化
plaidtech
PRO
0
700
アプリの "かわいい" を支えるアニメーションツールRiveについて
uetyo
0
110
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
How STYLIGHT went responsive
nonsquared
100
5.8k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Designing for Performance
lara
610
69k
Why Our Code Smells
bkeepers
PRO
339
57k
What's in a price? How to price your products and services
michaelherold
246
12k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
580
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.8k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
185
54k
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