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がもたらす新しいSwiftプログラミング / New Swi...
Search
darquro
September 06, 2019
Technology
3
1.5k
Property Wrappersがもたらす新しいSwiftプログラミング / New Swift programming with Property Wrappers
iOSDC Japan 2019 day1(2019/8/6) Track A LT 16:15
darquro
September 06, 2019
Tweet
Share
More Decks by darquro
See All by darquro
技術的負債を解消してくための組織づくり
darquro
1
870
Jailbreakと向き合おう
darquro
0
2k
ラクマでのSwiftUI導入方針とTips / Rakuma SwiftUI Introduction Policy and Tips
darquro
2
4.7k
Half modal comparision in iOS15
darquro
2
1.7k
2 Years Challenge as Engineering Manager in Rakuma
darquro
0
95
iOS View Class Design Basic
darquro
3
720
Swift 5 Exclusivity Enforcement
darquro
4
720
SDK連携を用いたAdMob活用法
darquro
1
960
ContributingSwift
darquro
0
78
Other Decks in Technology
See All in Technology
ガバメントクラウド単独利用方式におけるIaC活用
techniczna
3
270
来年もre:Invent2024 に行きたいあなたへ - “集中”と“つながり”で楽しむ -
ny7760
0
460
IaC運用を楽にするためにCDK Pipelinesを導入したけど、思い通りにいかなかった話
smt7174
1
110
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.6k
グローバル展開を見据えたサービスにおける機械翻訳プラクティス / dp-ai-translating
cyberagentdevelopers
PRO
1
150
AIを駆使したゲーム開発戦略: 新設AI組織の取り組み / sge-ai-strategy
cyberagentdevelopers
PRO
1
130
プロダクト成長に対応するプラットフォーム戦略:Authleteによる共通認証基盤の移行事例 / Building an authentication platform using Authlete and AWS
kakehashi
1
150
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
27
12k
CAMERA-Suite: 広告文生成のための評価スイート / ai-camera-suite
cyberagentdevelopers
PRO
3
270
CyberAgent 生成AI Deep Dive with Amazon Web Services / genai-aws
cyberagentdevelopers
PRO
1
480
WINTICKETアプリで実現した高可用性と高速リリースを支えるエコシステム / winticket-eco-system
cyberagentdevelopers
PRO
1
190
Forget efficiency – Become more productive without the stress
ufried
0
110
Featured
See All Featured
Unsuck your backbone
ammeep
668
57k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
7.9k
Code Reviewing Like a Champion
maltzj
519
39k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
Making Projects Easy
brettharned
115
5.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Transcript
Re:valua t ion https://fril.jp/ L ead & Delight User F
irst Ownership Fail Smart 1SPQFSUZ8SBQQFST͕ͨΒ͢ ৽͍͠4XJGUϓϩάϥϛϯά !J04%$+BQBO
J04&OHJOFFS 3BLVUFO JOD ϥΫϚ "CPVU.F EBSRVSP :VLJ,VSPEB
!EBSRVSP !EBSRVSP
1SPQFSUZ8SBQQFST
1SPQFSUZ8SBQQFST w "WBJMBCMF4XJGU w ϓϩύςΟΞΫηεʹԠͯ͡ڍಈΛXSBQ w ϓϩύςΟΠϯελϯε͝ͱʹσʔλΛอ࣋Մೳ w
ॳظԆ࣮ߦ
6TFS%FGBVMUT&YBNQMF @propertyWrapper struct UserDefault<T> { var wrappedValue: T
{ get { return UserDefaults.standard .object(forKey: key) as? T ?? defaultValue } set { UserDefaults.standard.set(newValue, forKey: key) } } }
6TFS%FGBVMUT&YBNQMF @propertyWrapper struct UserDefault<T> { let key: String
let defaultValue: T init(_ key: String, defaultValue: T) { self.key = key self.defaultValue = defaultValue UserDefaults.standard .register(defaults: [key: defaultValue]) } var wrappedValue: T { … } }
6TFS%FGBVMUT&YBNQMF struct Foo { @UserDefault("IS_LOGGED_IN", defaultValue: false) static
var isLoggedIn: Bool } Foo.isLoggedIn = true // UserDefaults.standard.object(forKey: "IS_LOGGED_IN") -> 1 Foo.isLoggedIn = false // UserDefaults.standard.object(forKey: "IS_LOGGED_IN") -> 0
6TFS%FGBVMUT&YBNQMF
4UBUF&YBNQMF struct LandmarkList: View { @State var showFavoriteOnly
= true var body: some View { NavigationView { List { Toggle(isOn: $showFavoriteOnly) { Text("Favorite Only") } … } … }
4UBUF&YBNQMF @propertyWrapper public struct State<Value> : DynamicProperty, BindingConvertible
{ …… /// The current state value. public var wrappedValue: Value { get nonmutating set } …… /// Produces the binding referencing this state value public var projectedValue: Binding<Value> { get } }
7BMJEBUJPO&YBNQMF @propertyWrapper struct Validate<Value> { var wrappedValue: Value?
var isValid: Bool { guard let value = wrappedValue else { return false } return validateion(value) } private let validateion: (Value) -> Bool private let messageClosure: (Value) -> String init(_ validation: @escaping (Value) -> Bool, message messageClosure: @escaping (Value) -> String) { self.validateion = validation self.messageClosure = messageClosure } }
7BMJEBUJPO&YBNQMF enum StringValidationType { case email case phoneNumber
var regex: String { switch self { case .email: return #"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za- z]{2,64}"# case .phoneNumber: return "^[0-9]{6,14}$" } } }
7BMJEBUJPO&YBNQMF extension Validate where Value == String {
init(_ type: StringValidationType) { self.init({ $0.range(of: type.regex, options: .regularExpression) != nil }, message: { "Error:\($0) does not match email" }) } }
7BMJEBUJPO&YBNQMF struct Foo { @Validate(.email) var email: String?
@Validate(.phoneNumber) var phoneNumber: String? var isValidAll: Bool { _email.isValid && _phoneNumber.isValid } } var foo = Foo() foo.email = "
[email protected]
" foo.phoneNumber = "09012341234" foo.isValidAll // -> "true"
நԽ
நԽ w ܧঝ w 1SPUPDPM w &YUFOTJPOT w
1SPQFSUZ8SBQQFST
நԽ 1SPQFSZ8SBQQFST ࣮ίετ ந 1SPUPDPM &YUFOTJPOT ܧঝ
ల ΞʔΩςΫνϟ ϑϨʔϜϫʔΫ σβΠϯύλʔϯ 044ϥΠϒϥϦ
·ͱΊ
·ͱΊ 1SPQFSUZ8SBQQFST w ΑΓநతʹػೳΛϓϩύςΟͷΈʹఏڙͰ͖Δ w ϘΠϥʔϓϨʔτͷলུʹͳΔ w !YYY@YYYYYYͱ͍ͬͨಠࣗͷγϯλοΫε
4XJGU&WPMVUJPO1SPQPTBM IUUQTHJUIVCDPNBQQMFTXJGUFWPMVUJPOCMPCNBTUFSQSPQPTBMTQSPQFSUZXSBQQFSTNE
5IBOLZPV