--- title: "What We Learned from Building a Production App with TCA" tags: "iPlayground2025" --- {%hackmd ByyUeRW_le %} # 📚 What We Learned from Building a Production App with TCA ### 👤 講者:YC Hsu ### 🕒 時間:15:00 – 15:20 --- ## 🧠 講題摘要 > TCA(The Composable Architecture) changed how we think about building apps. In this session, I’ll share our experience using TCA in production: what made us choose it, what surprised us, what helped us succeed, and what we suggest to you before you try TCA. --- ## 📝 重點筆記 One Dev -> A team Write fast -> Maintain long-term Simple Feature -> Complex Logic (More 3rd party dependency) ### 為什麼選擇 TCA - Sustainable 可維護性, Reusable 可重用性, Testable 可測試性, Composible 可組合性 - Shared mental model 單一事件流 - 容易 code review 可測試性 測試工具多  --- - 使用 snippet 做 template 增加新項目的建立效率 - 可組合性的模組讓 UI 的 fine tune 更加有效率 - 大部分的挑戰來自SwiftUI而不是TCA - 我覺得這句話貼切到蠻好笑的 - ### Should I use TCA? 如果專案還是以UIKit為主,可能就還不是很適合,如果開始使用SwiftUI就是不錯的時機可以開始嘗試 從小專案開始 (Side project 開始),先練功 [TCA Showcase](https://github.com/pointfreeco/swift-composable-architecture/discussions/1145) 看看別人怎麼做的 ### 總結 Build something small learn something big --- ## 💬 Q&A / 討論紀錄 (以下整理一些 YC 會後跟會眾聊到的問答) - Q: TCA 只能用在 SwiftUI 嗎? - A: 沒有,reducer 的邏輯要放在 UIKit 的 view 也可以,只是最能發揮 TCA 全力的會是 SwiftUI 專案 - Q: tuist 跟 XcodeGen 是不是很像? - A: 是也不是,大部分人認識到的,可以統一管理 Xcode 專案檔案避免衝突、或是可以生成 xcode project,這部分很像沒錯,但今天還有很多沒聊到的 tuist 優勢,像是他的 local cache 機制,可以大大加速 build time、甚至他們有 remote cache 的付費服務,讓團隊內跨開發者的 build time 提速,或是正在開發的 preview 機制,也是我很期待的新功能。btw,我還是很喜歡 tuist 用 Swift 語言來寫的這件事,比起 YAML 更讓人習慣XD - Q: TCA 的 reducer 中,如果愈來愈多複雜邏輯,action enum 裡面就有很多個 case,可以怎麼管理? - A: 如果多到很難維護,確實也是某種不好的 smell,你可以把大 feature 拆成小 feature(畢竟是可組合的架構,這件事很合理),例如把複雜的 textfield 邏輯拆出原本的畫面,變成獨立的 textfield feature。或者是,單純在 action enum 裡面幫不同類型的 action 做出 grouping,比如把對外的 delegate action 都放在 enum Delegate {} 裡面,或者是 view action 都放在 enum View {} 裡面(也可直接使用 TCA 提供的 @ViewAction),以上都可以讓 reducer 的可讀性、可維護性更佳 --- ## 🧩 延伸資源 / 投影片連結 - [The Composable Architecture](https://github.com/pointfreeco/swift-composable-architecture) - [13 的 iOS 開發配飯吃 • SwiftUI + TCA 系列](https://www.youtube.com/playlist?list=PL_ISTqHGWkNyN2qbc5wVDRyE6baEQ-BqU) - [Point Free 課程(需額外訂閱)(部分免費)](https://www.pointfree.co/collections/composable-architecture) - [TripAdvisor 導入 TCA 的精彩文章](https://medium.com/tripadvisor/the-evolution-of-native-engineering-at-tripadvisor-part-1-577cc0e36ec8 ) - [YC's personal app: Check-in Box (App Store)](https://apps.apple.com/tw/app/check-in-box-%E7%BC%BA%E6%87%89%E7%9B%92%E5%AD%90/id6474719999) - [YC's personal app: Check-in Box (TCA app GitHub repo)](https://github.com/Echim2016/check-in-box-ios) - [投影片下載連結](https://drive.google.com/file/d/1TnL8rCD6N11xgjMLTmsTvAV0WJVj10-k/view?usp=sharing) - [vocus 工商服務:Q3 正在招募優秀前端工程師中](https://www.cake.me/companies/vocus-cc/jobs) ## YC 補充的一些 TCA 延伸學習: 1. 可以先看 13 的中文教學影片: https://www.youtube.com/playlist?list=PL_ISTqHGWkNyN2qbc5wVDRyE6baEQ-BqU 2. 看出一點興趣,可以先看 point-free 這部免費的 intro: https://www.pointfree.co/collections/composable-architecture/composable-architecture-1-0/ep243-tour-of-the-composable-architecture-1-0-the-basics 3. 還是很有興趣,可以直接刷卡(自己或公司的)訂 point-free,把這個系列看完: https://www.pointfree.co/collections/composable-architecture/composable-architecture-1-0 4. 對 SwiftUI 小不熟的話,可以看這個有範例引導的 SwiftUI 講解,會用原生寫法來改寫一個 app,架構也很不錯: https://www.pointfree.co/collections/swiftui/modern-swiftui 5. 寫一個 TCA app 當練習,這個最有用XD 然後大家會把 TCA app 放在這邊跟開發者分享交流: https://github.com/pointfreeco/swift-composable-architecture/discussions/1145 --- TCA 不一定能直接幫助你的既有專案,但 point-free 其他小工具,其實都有導入現有專案的可能,推薦幾個好用的: * [swift-sharing](https://github.com/pointfreeco/swift-sharing):用好管理跨模組取用的 shared state 的工具,可以將資料存在 user default, file stoarage, in memory 等處,讓你在不同地方都能存取,而且可以被測試 * [swift-dependencies](https://github.com/pointfreeco/swift-dependencies):A dependency management library inspired by SwiftUI's `environment`. 可以拿來快速建立可控制、可測試的外部依賴,像是日期、clock、uuid、或是自定義依賴,之後你就能用像是 @Environment 的方式在 code 裡面注入 & 實作 * [swift-snapshot-testing](https://github.com/pointfreeco/swift-snapshot-testing):很多人只知道可以拿來做 UI 快照測試,但其實資料這種快照也可以做快照測試哦! * [swift-identified-collection](https://github.com/pointfreeco/swift-identified-collections):讓傳統的集合型別(最常用到的是 array)中的 item 成為 identifiable 的物件,讓 array 的查找、插入、移除變得更安全、更容易、更優雅 ## 雜談、心得 - 這個簡報的美感是設計師等級的 > 感覺像方格子內部簡報等級 > 我覺得可能是內部簡報 Template, 有找設計師設計過 - 去年 13 已經業配過 TCA 了,今年又來一個 XD,是不是該用了 > 還有TCA傳教士嗎~XDD > ~~一次性解決 TDD 難以達成的問題 XD~~ > 光是可測試性優先+單向資料流就超開心的了XD - Build something small, learn something big.
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up