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でProtocol Oriented をやってみた話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
kumapo
November 29, 2016
Technology
1.5k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
MVVMでProtocol Oriented をやってみた話
#potatotips 35 の発表資料です
kumapo
November 29, 2016
Other Decks in Technology
See All in Technology
AIは実装を速くする。では、私たちは何を今作るべきか?-立場を越えてリリースに向き合ったチーム開発の実践 / 20260801 Hiromi Nakaya and Naoki Takahashi
shift_evolve
PRO
3
330
え?フロントエンドエンジニアの ワイがインフラも!?
puku0x
0
100
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
9
3.2k
論語・武士道・産業革命から見る かわるもの、かわらないもの
ichimichi
8
2.2k
NetBoxを利用した作業効率化の試み_NetDevNight4
tnoha
0
450
20260722_品質と開発生産性の相互作用
magicpod
0
110
LangfuseによるLLMOps基盤の構築と活用事例
zozotech
PRO
1
260
AI ネイティブな組織に Gemini Enterprise Agent Platform がなぜ必要なのか
asei
1
160
データエンジニアこそ組織のオントロジーに向き合うべき — 問いに答えるAIから、事業を動かすAIへ
gappy50
7
3.2k
Pavlokで始める電撃駆動開発
sgrsn
0
160
コンポーネント名には何を含めるべきなのか? / what-should-be-included-in-component-names
airrnot1106
0
250
『三匹の子ぶた』から学ぶネットワークセキュリティの昔と今 / Network Security: Then and Now Through the Lens of The Three Little Pigs
nttcom
1
1.6k
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Optimizing for Happiness
mojombo
378
71k
Utilizing Notion as your number one productivity tool
mfonobong
4
500
30 Presentation Tips
portentint
PRO
1
360
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
360
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Abbi's Birthday
coloredviolet
3
9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
Transcript
MVVM Ͱ Protocol Oriented Λ ͬͯΈͨ ɹkumapo
ࣗݾհ • ຊۀ iOS ΤϯδχΞ • ͦͷΒͰαΠυϓϩδΣΫτΛ༑ਓͨͪͱ ͍ͬͯΔ
None
͖ΐ͏͢͜ͱ • αΠυϓϩδΣΫτͰॳΊͯMVVMΛ࠾༻ͯ͠Ҏདྷɺ ઃܭΛࢼߦࡨޡ͖ͯͨ͠ • ͖ΐ͏ ViewModelͰ Protocol Oriented ͬͯΈ
ͨΛ͠·͢ • Ξϓϩʔνͱͯ͠ ”Introduction to Protocol- Oriented MVVM by Natasha Murashev” ΛΞϨϯδ
MVVM Ͱࢼߦࡨޡͨ͠Օॴ • ViewModel Ͱͷ Data Formatting • σʔλʢModelͳͲʣ Λ
View͕ٻΊΔܗ ͱม͢ΔՕॴ • ViewModel ಉ࢜Ͱ ϩδοΫ͕ॏෳͯ͠͠· ͏
ྫ: TableViewController ͱ ViewController ͔ΒͳΔ 2ը໘
// ImageViewσʔλΛఏڙ͢ΔViewModel struct ShowStickerViewModel { var model: Sticker var imageURL:
URL? { return URL(string: model.imageURLString) } var placeholderImage: UIImage { return UIImage(named: “imgBlank”)! } Before: Data Formatting // TableViewCellͷImageViewσʔλΛఏڙ͢ΔViewModel struct StickerCellViewModel { var model: Sticker var imageURL: URL? { return URL(string: model.imageURLString) } var placeholderImage: UIImage { return UIImage(named: “imgBlank”)! }
// ImageViewఏڙ͢ΔσʔλΛఆΊͨϓϩτίϧ protocol ImageURLPresentable { var imageURL: URL? { get
} var placeholderImage: UIImage { get } } After: Data Formatting
// Protocol Extension ͯ͠ ImageURLPresentable ͷϓϩύςΟΛ࣮ // ܕ੍ͱͯ͠ Sticker Λࢦఆ
extension ViewModelType where Self: ImageURLPresentable, ModelType == Sticker { // σϑΥϧτͷ࣮: Sticker Λ Data Formatting ͢Δ var imageURL: URL? { return URL(string: model.imageURLString)ɹ } var placeholderImage: UIImage { return UIImage(named: “imgBlank”)! } After: Data Formatting // σʔλϑΥʔϚοτͷσϑΥϧτͷ࣮Λఏڙ͢Δϓϩτίϧ protocol ViewModelType { associatedtype ModelType // ϑΥʔϚοτରͷܕΛύϥϝʔλʔʹ var model: ModelType { get } }
struct ShowStickerViewModel: ViewModelType { typealias ModelType = Sticker var model:
ModelType } extension ShowStickerViewModel: ImageURLPresentable {} // ϓϩτίϧʹద߹ After: Data Formatting struct StickerCellViewModel: ViewModelType { typealias ModelType = Sticker var model: ModelType } extension StickerCellViewModel: ImageURLPresentable {} // ϓϩτίϧʹద߹ // ShowStickerViewController.swift imageView!.sd_setImage(with: viewModel.imageURL, placeholderImage: viewModel.placeholderImage)
·ͱΊ • ViewModel ͷ Data Formatting ͷ ϩδοΫΛ Protocol Extension
Λ༻͍ͯڞ௨Խͨ͠ • ViewModel ΛܕύϥϝʔλʔΛ࣋ͭϓϩτίϧʹద ߹ͤ͞Δ • Protocol Extension Λ༻͍ͯ Data Formattingͷσ ϑΥϧτ࣮Λఏڙ͢Δ • σϑΥϧτͷ࣮ରͷσʔλΛܕ੍ʹ͓ͯ͘͠
αϯϓϧίʔυ kumapo/ProtocolOrientedMVVM • ViewModel ϨΠϠʔͰͷData Formatting • ViewϨΠϠʔͰͷ Data Filling