@@ -101,7 +101,8 @@ graph TB
101101
102102以 ` TopicListViewModel ` 为例,展示 MVVM 的核心实现:
103103
104- ``` swift:12:93:App/Modules/Home/ViewModels/TopicListViewModel.swift
104+ ``` swift
105+ // App/Modules/Home/ViewModels/TopicListViewModel.swift
105106@MainActor
106107final class TopicListViewModel : ObservableObject {
107108 @Published private (set ) var topics: [Topic] = []
@@ -158,7 +159,8 @@ Repository 层抽象了数据访问逻辑,提供统一的接口。这种设计
158159- ** 可维护性** :数据源变更(如从 API 切换到本地数据库)只需修改 Repository 实现
159160- ** 单一职责** :Repository 只负责数据获取,不涉及业务逻辑
160161
161- ``` swift:22:66:App/Core/Networking/Repositories/TopicRepository.swift
162+ ``` swift
163+ // App/Core/Networking/Repositories/TopicRepository.swift
162164struct TopicRepository : TopicRepositoryProtocol {
163165 private let apiService: APIService
164166
@@ -174,7 +176,8 @@ struct TopicRepository: TopicRepositoryProtocol {
174176
175177项目使用自定义的依赖注入容器 ` AppContainer ` ,统一管理所有依赖项:
176178
177- ``` swift:16:50:App/Core/Dependency/AppContainer.swift
179+ ``` swift
180+ // App/Core/Dependency/AppContainer.swift
178181final class AppContainer : DependencyContainer {
179182 static let shared = AppContainer ()
180183
@@ -200,7 +203,8 @@ final class AppContainer: DependencyContainer {
200203
201204项目实现了通用的分页状态管理类 ` PaginationState ` ,用于统一管理列表的分页逻辑:
202205
203- ``` swift:11:38:App/Core/Pagination/PaginationState.swift
206+ ``` swift
207+ // App/Core/Pagination/PaginationState.swift
204208struct PaginationState <Item : Identifiable & Hashable > {
205209 private (set ) var items: [Item] = []
206210 private (set ) var currentPage: Int = 0
@@ -278,7 +282,8 @@ SwiftUI 作为 Apple 的现代 UI 框架,采用声明式编程范式,让 UI
278282
279283SwiftUI 的核心思想是通过描述 UI 的"状态"而非"步骤"来构建界面。这种声明式的方式让代码更加直观:
280284
281- ``` swift:33:68:App/Modules/Home/HomeView.swift
285+ ``` swift
286+ // App/Modules/Home/HomeView.swift
282287var body: some View {
283288 ScrollView {
284289 LazyVStack (spacing : AppTheme.compactSpacing ) {
@@ -315,7 +320,8 @@ SwiftUI 提供了多种状态管理方式,选择合适的属性包装器很重
315320
316321** 最佳实践:**
317322
318- ``` swift:11:21:App/Modules/Home/HomeView.swift
323+ ``` swift
324+ // App/Modules/Home/HomeView.swift
319325struct HomeView : View {
320326 @EnvironmentObject private var browsingHistory: BrowsingHistoryStore
321327 @Environment (\.colorScheme ) private var colorScheme
@@ -332,7 +338,8 @@ struct HomeView: View {
332338
333339通过 ViewModifier 实现可复用的样式,保持 UI 一致性:
334340
335- ``` swift:74:117:App/Core/Utils/AppTheme.swift
341+ ``` swift
342+ // App/Core/Utils/AppTheme.swift
336343extension View {
337344 func smthScaffoldBackground () -> some View {
338345 modifier (ScaffoldBackgroundModifier ())
@@ -400,7 +407,8 @@ var body: some View {
400407
401408在 SwiftUI 中处理异步操作时,使用 ` Task ` 和 ` async/await ` :
402409
403- ``` swift:81:95:App/Modules/Home/HomeView.swift
410+ ``` swift
411+ // App/Modules/Home/HomeView.swift
404412.onAppear {
405413 Task {
406414 await navigationViewModel.loadNavigationsIfNeeded ()
@@ -418,7 +426,8 @@ var body: some View {
418426
419427SwiftUI 支持使用 ` #if os() ` 进行平台特定代码:
420428
421- ``` swift:19:36:App/Components/ImageViewer.swift
429+ ``` swift
430+ // App/Components/ImageViewer.swift
422431var body: some View {
423432 #if os (iOS )
424433 ImageViewerUIKit (images : images, initialIndex : initialIndex, isPresented : $isPresented)
@@ -432,7 +441,8 @@ var body: some View {
432441
433442项目将 UI 拆分为可复用组件,每个组件职责单一:
434443
435- ``` swift:44:134:App/Modules/Home/TopicRowView.swift
444+ ``` swift
445+ // App/Modules/Home/TopicRowView.swift
436446struct TopicRowView : View {
437447 let topic: Topic
438448 let isVisited: Bool
@@ -477,7 +487,8 @@ struct TopicRowView: View {
477487
478488项目在 ` ContentView ` 中根据平台选择不同的导航方式:
479489
480- ``` swift:28:42:App/ContentView.swift
490+ ``` swift
491+ // App/ContentView.swift
481492var body: some View {
482493 Group {
483494 #if os (macOS )
@@ -495,7 +506,8 @@ var body: some View {
495506
496507** iOS 实现(TabView):**
497508
498- ``` swift:44:78:App/ContentView.swift
509+ ``` swift
510+ // App/ContentView.swift
499511private var tabLayout: some View {
500512 TabView (selection : $selection) {
501513 NavigationStack {
@@ -509,7 +521,8 @@ private var tabLayout: some View {
509521
510522** macOS 实现(NavigationSplitView):**
511523
512- ``` swift:117:145:App/ContentView.swift
524+ ``` swift
525+ // App/ContentView.swift
513526#if os (macOS )
514527private var macSidebarLayout: some View {
515528 NavigationSplitView (columnVisibility : $columnVisibility) {
@@ -535,7 +548,8 @@ private var macSidebarLayout: some View {
535548
536549** iOS(UIKit 实现):**
537550
538- ``` swift:39:62:App/Components/ImageViewer.swift
551+ ``` swift
552+ // App/Components/ImageViewer.swift
539553#if os (iOS )
540554private struct ImageViewerUIKit : UIViewControllerRepresentable {
541555 func makeUIViewController (context : Context) -> ImagePageViewController {
@@ -547,7 +561,8 @@ private struct ImageViewerUIKit: UIViewControllerRepresentable {
547561
548562** macOS(SwiftUI 实现):**
549563
550- ``` swift:64:215:App/Components/ImageViewer.swift
564+ ``` swift
565+ // App/Components/ImageViewer.swift
551566#if !os (iOS )
552567private struct ImageViewerSwiftUI : View {
553568 @State private var currentIndex: Int
@@ -573,7 +588,8 @@ private struct ImageViewerSwiftUI: View {
573588
574589** iOS(底部弹出):**
575590
576- ``` swift:134:141:App/Modules/Home/HomeView.swift
591+ ``` swift
592+ // App/Modules/Home/HomeView.swift
577593#if os (iOS )
578594.sheet (isPresented : $showProfileView) {
579595 ProfileView ()
@@ -584,7 +600,8 @@ private struct ImageViewerSwiftUI: View {
584600
585601** macOS(独立窗口):**
586602
587- ``` swift:142:149:App/Modules/Home/HomeView.swift
603+ ``` swift
604+ // App/Modules/Home/HomeView.swift
588605#elseif os (macOS )
589606.sheet (isPresented : $showProfileView) {
590607 ProfileView ()
@@ -626,7 +643,7 @@ graph LR
626643
627644项目使用 SwiftLint 进行代码规范检查,配置文件为 ` swiftlint.yml ` :
628645
629- ``` yaml:1:45:swiftlint.yml
646+ ``` yaml
630647disabled_rules :
631648 - identifier_name
632649 - trailing_whitespace
@@ -666,7 +683,7 @@ swiftlint --fix --config swiftlint.yml # 自动修复
666683
667684**Fastlane 集成:**
668685
669- ``` ruby:70:80:fastlane/Fastfile
686+ ` ` ` ruby
670687lane :lint do
671688 sh("swiftlint --config swiftlint.yml")
672689end
678695
679696项目使用 GitHub Actions 实现持续集成:
680697
681- ``` yaml:1:58:.github/workflows/ci.yml
698+ ` ` ` yaml
682699name: CI
683700
684701on:
@@ -731,7 +748,7 @@ graph TB
731748
732749Fastlane 的 `ci` lane 整合了代码检查和测试:
733750
734- ``` ruby:147:152:fastlane/Fastfile
751+ ` ` ` ruby
735752lane :ci do
736753 lint
737754 tests
751768
752769**ViewModel 测试示例:**
753770
754- ``` swift:1:60:SmthTests/TopicListViewModelTests.swift
771+ ` ` ` swift
772+ // SmthTests/TopicListViewModelTests.swift
755773final class TopicListViewModelTests: XCTestCase {
756774 func testInitialLoadFetchesTopics() async throws {
757775 let repository = StubTopicRepository(
0 commit comments