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
非機能品質を作り込むための実践アーキテクチャ
knih
3
730
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
12
3.4k
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
420
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
300
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
190
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
Wvlet: A New Flow-Style Query Language For Functional Data Modeling and Interactive Data Analysis - Trino Summit 2024
xerial
1
110
大幅アップデートされたRagas v0.2をキャッチアップ
os1ma
2
520
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
240
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
OpenShift Virtualizationのネットワーク構成を真剣に考えてみた/OpenShift Virtualization's Network Configuration
tnk4on
0
130
watsonx.ai Dojo #5 ファインチューニングとInstructLAB
oniak3ibm
PRO
0
160
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
66
4.5k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Visualization
eitanlees
146
15k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
The Pragmatic Product Professional
lauravandoore
32
6.3k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
A Philosophy of Restraint
colly
203
16k
4 Signs Your Business is Dying
shpigford
181
21k
Adopting Sorbet at Scale
ufuk
73
9.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
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