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
フルカイテン株式会社 採用資料
fullkaiten
0
40k
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
110
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.3k
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.1k
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
230
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
3
420
The Rise of LLMOps
asei
5
1.1k
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
350
Lexical Analysis
shigashiyama
1
150
Featured
See All Featured
A designer walks into a library…
pauljervisheath
203
24k
Building an army of robots
kneath
302
43k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Gamification - CAS2011
davidbonilla
80
5k
Done Done
chrislema
181
16k
Optimizing for Happiness
mojombo
376
70k
Side Projects
sachag
452
42k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Visualization
eitanlees
145
15k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
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