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
1年前に作った物と同じ目的のライブラリをまたSwift 3で作ってみた
Search
fromkk
November 29, 2016
Technology
0
1.2k
1年前に作った物と同じ目的のライブラリをまたSwift 3で作ってみた
TMValidatorを作った経験を活かしてSwift 3で同じ目的のライブラリを作ってみました。
fromkk
November 29, 2016
Tweet
Share
More Decks by fromkk
See All by fromkk
note社の全員野球で品質向上活動について / note_qa_challenge #iOS_test_teatime
fromkk
3
1.8k
1年分のデータが見たいと言われてやったこと/yearly_data_with_note
fromkk
0
890
note iOSチームの自動化 ver.2021/automation_with_iOS_team_on_note_ver2021
fromkk
0
1.9k
Bitrise体験会説明資料/bitrise_explore
fromkk
1
1k
noteのiOSアプリで実装したアクセシビリティの全て #iosdc #a /a11y_with_iOS_App_on_note
fromkk
2
3.4k
dSYMのアップロードで SPMを活用する/use_spm_with_upload_dsyms
fromkk
1
2.6k
Bitriseのリモートアクセス機能 #bitrise_meetup/remote_access_of_bitrise
fromkk
1
520
note社でのMagic Pod活用事例 #af_iosdc/magicpod_with_note
fromkk
2
10k
iOSには無いmacOS独自機能をCatalystで実装する #iosdc #d/make_macos_apps_with_catalyst
fromkk
9
2k
Other Decks in Technology
See All in Technology
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
990
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
380
Platform Engineering for Software Developers and Architects
syntasso
1
520
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
2
310
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
750
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
Introduction to Works of ML Engineer in LY Corporation
lycorp_recruit_jp
0
110
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9.1k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Typedesign – Prime Four
hannesfritz
40
2.4k
RailsConf 2023
tenderlove
29
900
What's new in Ruby 2.0
geeforr
343
31k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Site-Speed That Sticks
csswizardry
0
23
Transcript
1લʹ࡞ͬͨͱಉ͡ తͷϥΠϒϥϦΛ·ͨ Swift 3Ͱ࡞ͬͯΈͨ AKIBA.swift #7 (C) fromkk. 2016 1
ࣗݾհ ২Ԭɹ࠸ Timers inc.ͷiOSΤϯδχΞ Twitter: @fromkk Github: fromkk Qiita: fromkk
(C) fromkk. 2016 2
એ Χοϓϧ͚ΞϓϦͷPairy ͱ Ո͚ࣸਅڞ༗ΞϓϦͷ Famm ΛӡӦ͍ͯ͠Δ Ͱ ΤϯδχΞΛืू ͍ͯ͠·͢ʂ ڵຯͷ͋Δํֻ͓͚ɺ͘͠
http://timers-inc.com/ ΑΓ͓͍߹ΘͤԼ͍͞ʂ (C) fromkk. 2016 3
ࠓͷձࣾʹೖࣾͨ͠ࠒʹ TMValidator ͱ͍͏ ϥΠϒϥϦΛ࡞͠·ͨ͠ https://github.com/fromkk/TMValidator (C) fromkk. 2016 4
(C) fromkk. 2016 5
͋Ε͔Β1 • Swift 3͕ϦϦʔε͞ΕOSSʹͳͬͨ • ࣗࣾͷΞϓϦ50%͙Β͍͕Swiftʹͳͬͨ • ͦΕʹڞͳͬͯʑॻ͘ίʔυSwiftʹ (C) fromkk.
2016 6
ࠓಉ͡ϥΠϒϥϦΛ࡞ΔͱͲ͏ͳΔ͔ʁ (C) fromkk. 2016 7
࡞ͬͯΈͨ (C) fromkk. 2016 8
Valy https://github.com/fromkk/Valy • TMValidator ͱಉ͘͡όϦσʔγϣ ϯ༻ͷϥΠϒϥϦ • Swift 3 •
Carthage, CocoaPodsରԠ (C) fromkk. 2016 9
ࢥ TMValidator ͱ΄΅ಉ͡ 1.όϦσʔλʔΛ࡞ 2.ϧʔϧΛՃ 3.จࣈྻΛνΣοΫϝιουʹͤνΣοΫ݁ՌΛฦͯ͘͠Ε Δ (C) fromkk. 2016
10
Կނ࡞͔ͬͨ • աڈʹ࡞ͬͨͷ͕࣌ؒܦͭͱૈ͕ݟ͑Δ • ࣌Πέ͍ͯͨͱࢥ͍ͬͯͨઃܭվΊͯݟΔͱ͖ͬ͢Γ͠ ͍ͯͳ͍Օॴ͕ʹͭ͘ • SwiftΒ͍͠ॻ͖ํΛࢼͯ͠Έ͔ͨͬͨ (C) fromkk.
2016 11
TMValidatorͷαϯϓϧίʔυ UITextField *name = [[UITextField alloc] init]; name.text = @"໊લ";
TMValidatorField *fieldName = [TMValidatorField fieldWithValue:name.text andLabel:@"name" andElement:name]; [[fieldName addRule:[TMValidatorRuleRequired rule]] addRule:[TMValidatorRuleMaxLength ruleWithLength:@10]]; TMValidator *validator = [TMValidator validator]; [[validator addField:fieldName]; [validator runWithSuccesses:^(NSArray *successes) { NSLog(@"success! %@", successes); } andFailure:^(NSArray *errors) { NSLog(@"failure! %@", errors); }]; (C) fromkk. 2016 12
͍ (C) fromkk. 2016 13
Valyͷαϯϓϧίʔυ let value: String? = self.textField.text let result = Valy.factory()
.add(rule: ValyRule.required) .add(rule: ValyRule.maxLength(10)) .run(with: value) switch result { case .success: print("success!") case .failure(let rule): print("failed rule \(rule)") } (C) fromkk. 2016 14
ͳΜͱͳ͖ͬ͘͢Γʁ (C) fromkk. 2016 15
TMValidatorͷ • Objective-CͩͬͨͷͰશ͕ͯclassͷҝಠࣗϧʔϧ͕࡞Γਏ ͍ • ΤϥʔίʔυɾΤϥʔϝοηʔδΛ֤ϧʔϧʹ࣋ͨͤͯ͠·ͬ ͨͷͰࣗ༝͕ޮ͔ͳ͍ • ϧʔϧΛՃ͠ͳͯ͘νΣοΫϝιουΛ࣮ߦग़དྷͯ͠·͏ (C)
fromkk. 2016 16
ValyͰͷվળ • ϧʔϧAnyValidatorRuleϓϩτίϧΛద߹͍ͤͯ͑͞͞Ε ͍͍ • ΤϥʔϋϯυϦϯάόϦσʔτ݁Ռ͔Β࣮͢ΔͷͰࣗ ༝͕ߴ͍ʢͦͷίʔυྔ૿͑Δ͔ʣ • ܕফڈʹΑΓϧʔϧΛՃ͠ͳ͍ͱόϦσʔτ͕࣮ߦग़དྷͳ͍ (C)
fromkk. 2016 17
ܕফڈ (C) fromkk. 2016 18
ܕফڈ • ෳͷϓϩτίϧʹద߹ͨ͠ཁૉΛ࡞ • ݅ʹΑ֤ͬͯϓϩτίϧͷܕΛฦ͢ (C) fromkk. 2016 19
ValyͰͷܕফڈͷྫ protocol AnyValidator { var rules: [AnyValidatorRule] { get }
static func factory() -> AnyValidator static func factory(rules: [AnyValidatorRule]) -> AnyValidatable func add(rule: AnyValidatorRule) -> AnyValidatable func add(rules: [AnyValidatorRule]) -> AnyValidatable } protocol AnyValidatable: AnyValidator { func run(with value: String?) -> ValidatorResult } Valy.factory().run(with: value) //NG! Value of type 'AnyValidator' has no member 'run' Valy.factory().add(rule: ValyRule.required).run(with: value) //OK! (C) fromkk. 2016 20
·ͱΊ • ࣌ͷྲྀΕʹܦݧʹΑͬͯઃܭͷ෯͕૿͑ͨʢؾ͕͢Δʣ • ܕফڈΛར༻͢ΕίʔυΛॻ͘ଆʹ੍ݶΛՃ͑Δࣄ͕ग़དྷ ͯόάΛੜΈਏ͍ (C) fromkk. 2016 21
͍ͬͯ͏༰Ͱ Swift Advent Calendar 2016ʹ هࣄΛॻ͘ͷͰ ετοΫ ͍͍Ͷ Լ͍͞ʂ (C)
fromkk. 2016 22
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝ ·ͨ͠ʂ (C) fromkk. 2016 23