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
MVVM for iOS
Search
laiso
March 12, 2014
Technology
4
2.1k
MVVM for iOS
iOSアプリケーションの開発にMVVMアーキテクチャの考えを持ち込んで設計を見直そうという話をしました
laiso
March 12, 2014
Tweet
Share
More Decks by laiso
See All by laiso
Firebaseを使った成長するモバイルアプリのための高速なプロダクト開発 / Rapid Mobile Application Development using #Firebase
laiso
4
4.8k
iOSエンジニアが知るべきProgressive Web Apps開発のエッセンス / PWA Essentials for iOS Developer - iOSDC 2018
laiso
6
4.1k
Service Workersを使ったウェブアプリのアーキテクチャ / Web App Architecture on Service Workers
laiso
3
2k
React Native vs iOS エンジニア - iOSDC 2017
laiso
2
720
Objective-C Toolchain in 2017
laiso
0
1.4k
Quickで体験するテストの構造化
laiso
2
2.7k
Apple Pay in 5 minutes
laiso
0
160
Apple Pay In The Real World
laiso
0
130
スタートアップの人材獲得戦略
laiso
2
11k
Other Decks in Technology
See All in Technology
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
760
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
Terraform Stacks入門 #HashiTalks
msato
0
360
Engineer Career Talk
lycorp_recruit_jp
0
190
Application Development WG Intro at AppDeveloperCon
salaboy
0
200
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
260
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
CDCL による厳密解法を採用した MILP ソルバー
imai448
3
160
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
490
OTelCol_TailSampling_and_SpanMetrics
gumamon
1
220
飲食店データの分析事例とそれを支えるデータ基盤
kimujun
0
180
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
150
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
43
13k
Rails Girls Zürich Keynote
gr2m
94
13k
4 Signs Your Business is Dying
shpigford
180
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Typedesign – Prime Four
hannesfritz
40
2.4k
Gamification - CAS2011
davidbonilla
80
5k
Code Review Best Practice
trishagee
64
17k
Docker and Python
trallard
40
3.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
A Modern Web Designer's Workflow
chriscoyier
693
190k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Transcript
MVVM for iOS MVVM for iOS @laiso @laiso 03/12/2014 03/12/2014
potatotips#5(at COOKPAD) potatotips#5(at COOKPAD)
laiso is NOT laiso is NOT ແ৬ ແ৬ http://lai.so/
ΤϯλʔϓϥΠζ ΤϯλʔϓϥΠζObjective-C Objective-C ͷੈքͱ ͷੈքͱ
มߋ͕πϥ͍ มߋ͕πϥ͍iOS iOSΞϓϦέʔ ΞϓϦέʔ γϣϯ γϣϯ Fat & Massive ViewController
God object, Singleton UI testing is very hard
มߋʹཱ͔ͪ͏ มߋʹཱ͔ͪ͏iOS iOSΞϓϦ ΞϓϦ έʔγϣϯ έʔγϣϯ OSΞοϓσʔτʹΑΓΫϥΠΞϯτͷڥ͕ͲΜͲΜߋ ৽͞ΕͯΏ͘ ϢʔβʔαΠυͰಈ͘ͿΜݖݶӨڹ͕େ͖͘มߋʹϦε Ϋ͕͋Δ(࣭ཁٻ͕ߴ͍)
ωΠςΟϒUIͷมߋHTML+JavaScriptͳͲΑΓॏ͘ͳΓ ͕ͪ
ઃܭվળ ઃܭվળ ίʔυΛཧղ͍ͨ͘͢͠͠ ςετΛॻ͖͍ͨ͘͢͠ มߋʹڧ͘ͳΓɺߴʹ։ൃ͍ͨ͠
MVVM MVVM (Model View ViewModel) (Model View ViewModel)
MVVM MVVM Windows / .NET WPF Silverlight JavaScript Framework AngularJS
KnockoutJS
MVC MVC MVVM MVVM
Cocoa vs MVVM Cocoa vs MVVM ϓϥοτϑΥʔϜຖʹMVCͷߟ͑ํҧ͏ (Rails,Cocoa,Smalltalk) Controller !=
ViewController MVVM View == View+ViewController
ViewController ViewController Ϗϡʔͷίϯτϩʔϥʔ ΞϓϦέʔγϣϯ/Ϟδϡʔϧ"ͷ"ίϯτϩʔϥʔͰͳ ͍ ରͷϏϡʔΛอ໋࣋ͯ͠ྩ͢Δ
ViewModel ViewModel View-ModelɻϏϡʔͷͨΊͷϞσϧ σʔλόΠϯσΟϯάͷΈͰσʔλΛϏϡʔͱଓ Ϗϡʔͳ͠ͰΠϯλʔϑΣΠεΛૢ࡞Ͱ͖Δ
MVVM MVVMͷத৺ͱͳΔߟ͑ํ ͷத৺ͱͳΔߟ͑ํ એݴతͳViewςϯϓϨʔτ σʔλόΠϯσΟϯά
Storyboard(IB) Storyboard(IB) એݴతͳViewςϯϓϨʔτ Storyboard != View தΞοϓϧͷಠࣗن֨ͷXMLςΩετϑΝΠϧ Xcode͕GUIσβΠϯπʔϧͱͯ͠ղऍ͢Δɻ ຊϏϡʔΛએݴͯ͠ΠϕϯτΛଓ͢Δ͜ͱ ʮUIύʔπΛը໘ʹදࣔͤ͞ΔͨΊͷπʔϧʯҎ্ͷ
ҙຯ߹͍͕͋Δ
σʔλόΠϯσΟϯά σʔλόΠϯσΟϯά = Co‐ = Co‐ coa coaόΠϯσΟϯά όΠϯσΟϯά? ?
Mac OS X͚ͷσʔλόΠϯσΟϯάػߏ iOSʹདྷͯͳ͍ see "Cocoa Bindings Programming Topics" http://news.mynavi.jp/special/2005/cocoamvc/menu.html
σʔλόΠϯσΟϯά σʔλόΠϯσΟϯά = Re‐ = Re‐ activeCocoa activeCocoa https://github.com/ReactiveCocoa/ReactiveCocoa
ReactiveCocoa ReactiveCocoa Mac/iOSͰϦΞΫςΟϒϓϩάϥϛϯάΛ࣮ݱ͢Δҝͷϥ ΠϒϥϦ ؔܕϓϩάϥϛϯά෩ͷݴޠDSL
ReactiveCocoa ReactiveCocoaͱ ͱGitHub GitHub GitHubࣾͷਓୡΛϝΠϯʹ։ൃ͞Ε͍ͯΔ GitHub͕Windows൛ΞϓϦέʔγϣϯΛ։ൃ͠ग़ͨ͋͠ ͨΓ͔Β׆ൃʹ GitHubʹC#/.NETܥͷ࣮ྗऀ͕͍ΔɻXamarin/Mono ͬͯΔͦ͏ GitHubͷMacΞϓϦReactiveCocoaΛͬͯMVVMΛ࣮
ݱ͍ͯ͠Δ
ReactiveCocoa ReactiveCocoa มߋΛγάφϧͱ͍͏ΦϒδΣΫτͰදݱͰ͖ΔͷͰɺ ViewModelViewͷৄࡉΛΔඞཁ͕ͳ͍ ViewModelΛରʹςετ͕ॻ͚Δ
RVMViewModel RVMViewModel ReactiveCocoa/ReactiveViewModel ಛఆͷγάφϧͷΠϯλʔϑΣΠεΛఆٛͨ͠ϕʔεΫϥ ε ViewModelͰܧঝͯ͠͏
ViewModel ViewModelΛࠐΉ ΛࠐΉ ViewControllerͷॳظԽ࣌ʹ // TipsListViewController - (id)init { //
... self.viewModel = [[TipsListViewModel alloc] init]; return self; }
ViewModel ViewModelΛࠐΉ ΛࠐΉ StoryboardͷγʔέϯεͰInject // TipsListViewController - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{ if ([[segue identifier] isEqualToString:@"showDetail"]) { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; TipsDetailViewController *viewController = segue.destinationViewController; // ભҠઌͷViewModelΛॳظԽͯ͠ฦ͢ viewController.viewModel = [self.viewModel detailViewModelForIndexPath:indexPath]; } }
ViewModel ViewModelͷ୯ମςετ ͷ୯ମςετ it (@"ViewModelͷςετ", ^{ TipsDetailViewModel *viewModel = [[TipsDetailViewModel
alloc] initWithModel:tips] expect(viewModel.title).to.equal(@"MVVM for iOS"); expect(viewModel.subTitle).to.equal(@""); expect(viewModel.author).to.equal(@"laiso"); });
Pros Pros UIͱϩδοΫͷ ςετ͘͢͠ͳΔ ࠶ར༻͘͢͠ͳΔ ϦΞΫςΟϒUIԽͰͷԠੑ্
Cons Cons هड़ྔ͕૿͑Δ ReactiveCocoaͷޠኮΛशಘ͢Δඞཁ͕͋Δ ࣮ݧతͰ࣮ફ͢Δͷ͕͍͠ ϑϨʔϜϫʔΫଆͷڧ੍ྗͳ͍ͷͰͨͩʹͳͬ ͯΠϚΠνͳײ͡ͰऴΘΔՄೳੑ͋Δ UIʹର͢ΔςετΧόʔͰ͖ͳ͍
͜Ε͔Β ͜Ε͔Β 1. ෳͷ։ൃऀ͕͔͔ΘΔΑ͏ͳෳࡶͰنͷେ͖ͳΞϓϦ έʔγϣϯΛ͏·͘։ൃͰ͖ΔΑ͏ʹ͢Δ 2. ςετͰอޢͰ͖ΔൣғΛ૿ͯ͠ϦϑΝΫλϦϯάͰί ʔυͷഊΛ͗ߴʹϦϦʔεͰ͖ΔΑ͏ʹ͢Δ 3. ํ๏ͷಋೖͰͳ͘എܠͷ՝ʹؔ৺Λ࣋ͪࣗͨͪͰ
ߟ͑Δ͜ͱͰվળ͍ͯ͘͠
ࢀߟࢿྉ ࢀߟࢿྉ Code Reuse with MVVM Model-View-ViewModel for iOS |
Teehan+Lax ReactiveCocoa/Documentation/FrameworkOverview.md at master · ReactiveCocoa/ReactiveCocoa GUI Architectures
Functional Reactive Program‐ Functional Reactive Program‐ ming on iOS ming
on iOS https://leanpub.com/iosfrp
Xamarin.iOS Xamarin.iOS C#͚ͷMVVMαϙʔτϥΠϒϥϦ https://github.com/MvvmCross/MvvmCross https://github.com/reactiveui/ReactiveUI
Thank You Thank You