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
710
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
内製化によるシステムモダナイゼーションの実践
kazokmr
3
530
バクラクにおける可観測性向上の取り組み
yuu26
2
230
TinyMLの技術動向
kyotomon
2
260
CI/CDやテスト自動化の開発プロジェクトへの適用
megascus
3
650
都市伝説バスターズ「WebアプリのボトルネックはDBだから言語の性能は関係ない」 - Kaigi on Rails 2024
osyoyu
13
4.8k
分布で見る効果検証入門 / ai-distributional-effect
cyberagentdevelopers
PRO
2
550
で、ValhallaのValue Classってどうなったの?
skrb
1
560
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.6k
Why and Why not of enabling swap in Kubernetes
hwchiu
0
470
ActiveRecord SQLインジェクションクイズ (Rails 7.1.3.4)
kozy4324
9
2.1k
リファクタリングへの耐性が高いモデルベースの統合テストの紹介 / Model-Base Integration Test for Refactoring
yuitosato
5
1.5k
Nix入門パラダイム編
asa1984
1
160
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Designing Experiences People Love
moore
138
23k
The Language of Interfaces
destraynor
154
24k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
What's new in Ruby 2.0
geeforr
342
31k
Gamification - CAS2011
davidbonilla
80
5k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
BBQ
matthewcrist
85
9.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
360
RailsConf 2023
tenderlove
29
870
Raft: Consensus for Rubyists
vanstee
136
6.6k
KATA
mclloyd
29
13k
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