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
730
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
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
C++26 エラー性動作
faithandbrave
2
770
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
3
2.4k
DUSt3R, MASt3R, MASt3R-SfM にみる3D基盤モデル
spatial_ai_network
2
180
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
350
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
850
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
290
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
150
なぜCodeceptJSを選んだか
goataka
0
160
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
270
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
Featured
See All Featured
A better future with KSS
kneath
238
17k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Visualization
eitanlees
146
15k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Six Lessons from altMBA
skipperchong
27
3.5k
Gamification - CAS2011
davidbonilla
80
5.1k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
4 Signs Your Business is Dying
shpigford
181
21k
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