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.6k
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
940
Jailbreakと向き合おう
darquro
0
2.3k
ラクマでのSwiftUI導入方針とTips / Rakuma SwiftUI Introduction Policy and Tips
darquro
2
5k
Half modal comparision in iOS15
darquro
2
1.9k
2 Years Challenge as Engineering Manager in Rakuma
darquro
0
110
iOS View Class Design Basic
darquro
3
740
Swift 5 Exclusivity Enforcement
darquro
4
780
SDK連携を用いたAdMob活用法
darquro
1
1k
ContributingSwift
darquro
0
82
Other Decks in Technology
See All in Technology
Tirez profit de Messenger pour améliorer votre architecture
tucksaun
1
150
大規模アジャイル開発のリアル!コミュニケーション×進捗管理×高品質
findy_eventslides
0
570
モノリスの認知負荷に立ち向かう、コードの所有者という思想と現実
kzkmaeda
0
110
SpannerとAurora DSQLの同時実行制御の違いに想いを馳せる
masakikato5
0
570
コード品質向上で得られる効果と実践的取り組み
ham0215
2
200
職種に名前が付く、ということ/The fact that a job title has a name
bitkey
1
250
Keynote - KCD Brazil - Platform Engineering on K8s (portuguese)
salaboy
0
130
スケールアップ企業のQA組織のバリューを最大限に引き出すための取り組み
tarappo
4
960
どっちの API SHOW?SharePoint 開発における SharePoint REST API Microsoft Graph API の違い / Which API show? Differences between Microsoft Graph API and SharePoint REST API
karamem0
0
110
頻繁リリース × 高品質 = 無理ゲー? いや、できます!/20250306 Shoki Hyo
shift_evolve
0
160
React Server Componentは 何を解決し何を解決しないのか / What do React Server Components solve, and what do they not solve?
kaminashi
6
1.2k
OCI見積もり入門セミナー
oracle4engineer
PRO
0
120
Featured
See All Featured
Navigating Team Friction
lara
184
15k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
51
2.4k
How to train your dragon (web standard)
notwaldorf
91
5.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
8
700
GraphQLとの向き合い方2022年版
quramy
45
14k
We Have a Design System, Now What?
morganepeng
51
7.5k
Side Projects
sachag
452
42k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
102
18k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.5k
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