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
Clean Swift Workshop
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Chiaote Ni
November 08, 2020
Programming
830
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Clean Swift Workshop
Chiaote Ni
November 08, 2020
More Decks by Chiaote Ni
See All by Chiaote Ni
MCP - iPlayground
chiaoteni
0
140
Swift Testing - iPlayground
chiaoteni
0
310
Swift Package Manager
chiaoteni
0
160
Swift Smart KeyPath
chiaoteni
0
1.4k
Other Decks in Programming
See All in Programming
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
リアルな遅延を測る仕様
kota_yata
1
140
Building an Out-of-Order CPU
latte72
0
600
信頼性の目標を誰も求めてない
shubox
0
480
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
120
初めての模倣学習とVLA
natsutan
0
440
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
960
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.7k
[DroidKaigi 26] How We Moved from Android Studio to Slack
thisaay
0
190
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
0
170
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
2
990
XHTMLが残したもの
yosuke_furukawa
PRO
1
380
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.6k
Skip the Path - Find Your Career Trail
mkilby
1
220
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Chasing Engaging Ingredients in Design
codingconduct
0
300
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Building AI with AI
inesmontani
PRO
1
1.2k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
640
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
660
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
430
Navigating Team Friction
lara
192
16k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
590
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
410
Transcript
Clean Swift A better architecture to make project testable iOS@Taipei
艾倫 Ni & William Kuo
What is Clean Swift?
ViewController
Scene
Interactor Presenter ViewController
ViewController Interactor Presenter Display Logic Business Logic Presentation Logic ViewController
Interactor Presenter Display Logic Business Logic Presenta tion Logic
ViewControll Interact Presenter Display Logic Business Logic Presentation Logic Worker
Worker Worker
Worker ORM / DB Local API Network / API Network
API ViewControll Interact Presenter Display Logic Business Logic Presentation Logic
Worker ViewControll Interact Presenter Display Logic Business Logic Presentation Logic
I13N Calculate Thumbnail resize Parse video’s metadata
Interactor Presenter ViewController Request Response ViewModel
None
Boundary
viewContorller interactor presentor in out in out DisplayLogic in out
Boundary Boundary Boundary BusinessLogic Presentation Logic
protocol MeetupEventListDisplayLogic: AnyObject { func displayMeetupEvents(viewModel: MeetupEventList.FetchEvents.ViewModel) func displayUpdateHistoryEvent(viewModel: MeetupEventList.UpdateHistoryEvent.ViewModel)
} final class MeetupEventListViewController: UIViewController, MeetupEventListDisplayLogic { } protocol MeetupEventListBusinessLogic { func fetchMeetupEvents(request: MeetupEventList.FetchEvents.Request) func tapFavorite(request: MeetupEventList.TapFavorite.Request) func subscribeFavoriteUpdate(request: MeetupEventList.SubscribeFavoriteUpdate.Request) func unsubscribeFavoriteUpdate(request: MeetupEventList.UnsubscribeFavoriteUpdate.Request) } final class MeetupEventListInteractor: MeetupEventListBusinessLogic { } protocol MeetupEventListPresentationLogic { func presentMeetupEvents(response: MeetupEventList.FetchEvents.Response) func presentUpdateHistoryEvent(response: MeetupEventList.UpdateHistoryEvent.Response) } final class MeetupEventListPresenter: MeetupEventListPresentationLogic { }
BusinessLogic in out Boundary private func private func private func
private func Test
What’s more?
ViewController Interactor DataStore Router Data Passing Routing
Workshop Practice
None
基礎版 進階版
None
None
Interactor Presenter ViewController Request Response ViewModel struct Request { }
struct ViewModel { let historyEvents: [] let recentlyEvents: [] } struct Response { let recentlyEvents: [EventResponseItem] let historyEvents: [EventResponseItem] }
enum MeetupEventList { enum FetchEvents { struct Request { }
struct Response { let recentlyEvents: [EventResponseItem] let historyEvents: [EventResponseItem] } struct ViewModel { let historyEvents: [DisplayHistoryEvent] let recentlyEvents: [DisplayRecentlyEvent] } } }
Presentation Model
struct DisplayRecentlyEvent { let id: String let title: String let
dateText: String let hostName: String let coverImageURL: URL? }
struct DisplayHistoryEvent { let id: String let title: String let
dateText: String let hostName: String let coverImageURL: URL? let favoriteButtonColor: UIColor }
How?
class MeetupEventListViewController: UIViewController { } var recentlyEvents: [MeetupEvent] = []
var historyEvents: [MeetupEvent] = [] ViewController (MVC)
var recentlyEvents: [MeetupEventList.DisplayRecentlyEvent] = [] var historyEvents: [MeetupEventList.DisplayHistoryEvent] = []
protocol MeetupEventListDisplayLogic: AnyObject { func displayMeetupEvents( viewModel: MeetupEventList.FetchEvents.ViewModel ) } class MeetupEventListViewController: UIViewController, MeetupEventListDisplayLogic { } ViewController (Clean Swift)
meetupEventListAPI.fetchMeetupEvents { [weak self] result in guard let self =
self else { return } switch result { case let .success((recentlyEvents, historyEvents)): self.recentlyEvents = self.recentlyEvents self.historyEvents = self.historyEvents self.tableView.reloadData() case let .failure(error): print("#### error -> \(error)") } } loadData( ) (MVC)
let request: MeetupEventList.FetchEvents.Request = .init() interactor?.fetchMeetupEvents(request: request) loadData( ) (Clean
Swift)
func configureCell(with meetupEvent: MeetupEvent) { titleLabel.text = meetupEvent.title hostNameLabel.text =
meetupEvent.hostName if let eventDate = meetupEvent.date { dateLabel.text = getDateText(with: eventDate) } else { dateLabel.text = "" } coverImageView.image = nil if let coverImageUrl = meetupEvent.coverImageLink, let url = URL(string: coverImageUrl) { coverImageView.isHidden = false coverImageView.kf.setImage(with: url) } else { coverImageView.isHidden = true } } Configure Cell (MVC)
func configureCell( with meetupEvent: MeetupEventList.DisplayRecentlyEvent ) { titleLabel.text = meetupEvent.title
hostNameLabel.text = meetupEvent.hostName dateLabel.text = meetupEvent.dateText coverImageView.image = nil if let url = meetupEvent.coverImageURL { coverImageView.isHidden = false coverImageView.kf.setImage(with: url) } else { coverImageView.isHidden = true } } Configure Cell (Clean Swift)
protocol MeetupEventListBusinessLogic { func fetchMeetupEvents( request: MeetupEventList.FetchEvents.Request ) } class
MeetupEventListInteractor: MeetupEventListBusinessLogic{ var fetchMeetupEventWorker: MeetupEventListAPIWorker func fetchMeetupEvents( request:MeetupEventList.FetchEvents.Request ) { } } Interactor (Clean Swift)
protocol MeetupEventListPresentationLogic { func presentMeetupEvents( response: MeetupEventList.FetchEvents.Response ) } class
MeetupEventListPresenter:MeetupEventListPresentationLogic { func presentMeetupEvents( response: MeetupEventList.FetchEvents.Response ){ } } Presenter (Clean Swift)
活動時間: 每週⼆ pm: 8:30 ~ 10:00 (每⽉第⼀週休) 活動地點:線上聚會 || Meet.jobs
辦公室 (感謝Meet.jobs 提供場地)
聯絡資訊(email) 聯絡資訊(LinkedIn) 我們在招⼈~ beanfun!的iOS團隊需要你 ⽬前我們正在以Clean Swift為主架構 重構整個beanfun! App ⽬前預計明年1⽉會上線
如果你對這個機會有興趣,想了解更多資訊 歡迎email給我,或加我LinkedIn聊聊唷
練習專案 完成版 Clean Swift 討論群
Thanks for your attention.