library-picturebook-activity/.claude/skills/ui-ux-pro-max/data/stacks/swiftui.csv
aid 418aa57ea8 Day4: 超管端设计优化 + UGC绘本创作社区P0实现
一、超管端设计优化
- 文档管理SOP体系建立,docs目录重组
- 统一用户管理:跨租户全局视角,合并用户管理+公众用户
- 活动监管全模块重构:全部活动(统计卡片+阶段筛选+SuperDetail详情页)、报名数据/作品数据/评审进度(两层合一扁平列表)、成果发布(去Tab+统计+隐藏写操作)
- 菜单精简:移除评委管理/评审规则/通知管理
- Bug修复:租户编辑丢失隐藏菜单、pageSize限制、主色统一

二、UGC绘本创作社区P0
- 数据库:10张新表(user_works/user_work_pages/work_tags等)
- 子女账号独立化:Child升级为独立User,家长切换+独立登录
- 用户作品库:CRUD+发布审核,8个API
- AI创作流程:提交→生成→保存到作品库,4个API
- 作品广场:首页改造为推荐流,标签+搜索+排序
- 内容审核(超管端):作品审核+作品管理+标签管理
- 活动联动:WorkSelector作品选择器
- 布局改造:底部5Tab(发现/创作/活动/作品库/我的)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 22:20:25 +08:00

11 KiB

1NoCategoryGuidelineDescriptionDoDon'tCode GoodCode BadSeverityDocs URL
21ViewsUse struct for viewsSwiftUI views are value typesstruct MyView: Viewclass MyView: Viewstruct ContentView: View { var body: some View }class ContentView: ViewHighhttps://developer.apple.com/documentation/swiftui/view
32ViewsKeep views small and focusedSingle responsibility for each viewExtract subviews for complex layoutsLarge monolithic viewsExtract HeaderView FooterView500+ line View structMedium
43ViewsUse body computed propertybody returns the view hierarchyvar body: some View { }func body() -> some Viewvar body: some View { Text("Hello") }func body() -> TextHigh
54ViewsPrefer composition over inheritanceCompose views using ViewBuilderCombine smaller viewsInheritance hierarchiesVStack { Header() Content() }class SpecialView extends BaseViewMedium
65StateUse @State for local stateSimple value types owned by view@State for view-local primitives@State for shared data@State private var count = 0@State var sharedData: ModelHighhttps://developer.apple.com/documentation/swiftui/state
76StateUse @Binding for two-way dataPass mutable state to child views@Binding for child input@State in child for parent data@Binding var isOn: Bool$isOn to pass bindingMediumhttps://developer.apple.com/documentation/swiftui/binding
87StateUse @StateObject for reference typesObservableObject owned by view@StateObject for view-created objects@ObservedObject for owned objects@StateObject private var vm = ViewModel()@ObservedObject var vm = ViewModel()Highhttps://developer.apple.com/documentation/swiftui/stateobject
98StateUse @ObservedObject for injected objectsReference types passed from parent@ObservedObject for injected dependencies@StateObject for injected objects@ObservedObject var vm: ViewModel@StateObject var vm: ViewModel (injected)Highhttps://developer.apple.com/documentation/swiftui/observedobject
109StateUse @EnvironmentObject for shared stateApp-wide state injection@EnvironmentObject for global stateProp drilling through views@EnvironmentObject var settings: SettingsPass settings through 5 viewsMediumhttps://developer.apple.com/documentation/swiftui/environmentobject
1110StateUse @Published in ObservableObjectAutomatically publish property changes@Published for observed propertiesManual objectWillChange calls@Published var items: [Item] = []var items: [Item] { didSet { objectWillChange.send() } }Medium
1211ObservableUse @Observable macro (iOS 17+)Modern observation without Combine@Observable class for view modelsObservableObject for new projects@Observable class ViewModel { }class ViewModel: ObservableObjectMediumhttps://developer.apple.com/documentation/observation
1312ObservableUse @Bindable for @ObservableCreate bindings from @Observable@Bindable var vm for bindings@Binding with @Observable@Bindable var viewModel$viewModel.name with @ObservableMedium
1413LayoutUse VStack HStack ZStackStandard stack-based layoutsStacks for linear arrangementsGeometryReader for simple layoutsVStack { Text() Image() }GeometryReader for vertical listMediumhttps://developer.apple.com/documentation/swiftui/vstack
1514LayoutUse LazyVStack LazyHStack for listsLazy loading for performanceLazy stacks for long listsRegular stacks for 100+ itemsLazyVStack { ForEach(items) }VStack { ForEach(largeArray) }Highhttps://developer.apple.com/documentation/swiftui/lazyvstack
1615LayoutUse GeometryReader sparinglyOnly when needed for sizingGeometryReader for responsive layoutsGeometryReader everywhereGeometryReader for aspect ratioGeometryReader wrapping everythingMedium
1716LayoutUse spacing and padding consistentlyConsistent spacing throughout appDesign system spacing valuesMagic numbers for spacing.padding(16) or .padding().padding(13), .padding(17)Low
1817LayoutUse frame modifiers correctlySet explicit sizes when needed.frame(maxWidth: .infinity)Fixed sizes for responsive content.frame(maxWidth: .infinity).frame(width: 375)Medium
1918ModifiersOrder modifiers correctlyModifier order affects renderingBackground before padding for full coverageWrong modifier order.padding().background(Color.red).background(Color.red).padding()High
2019ModifiersCreate custom ViewModifiersReusable modifier combinationsViewModifier for repeated stylingDuplicate modifier chainsstruct CardStyle: ViewModifier.shadow().cornerRadius() everywhereMediumhttps://developer.apple.com/documentation/swiftui/viewmodifier
2120ModifiersUse conditional modifiers carefullyAvoid changing view identityif-else with same view typeConditional that changes view identityText(title).foregroundColor(isActive ? .blue : .gray)if isActive { Text().bold() } else { Text() }Medium
2221NavigationUse NavigationStack (iOS 16+)Modern navigation with type-safe pathsNavigationStack with navigationDestinationNavigationView for new projectsNavigationStack { }NavigationView { } (deprecated)Mediumhttps://developer.apple.com/documentation/swiftui/navigationstack
2322NavigationUse navigationDestinationType-safe navigation destinations.navigationDestination(for:)NavigationLink(destination:).navigationDestination(for: Item.self)NavigationLink(destination: DetailView())Medium
2423NavigationUse @Environment for dismissProgrammatic navigation dismissal@Environment(\.dismiss) var dismisspresentationMode (deprecated)@Environment(\.dismiss) var dismiss@Environment(\.presentationMode)Low
2524ListsUse List for scrollable contentBuilt-in scrolling and stylingList for standard scrollable contentScrollView + VStack for simple listsList { ForEach(items) { } }ScrollView { VStack { ForEach } }Lowhttps://developer.apple.com/documentation/swiftui/list
2625ListsProvide stable identifiersUse Identifiable or explicit idIdentifiable protocol or id parameterIndex as identifierForEach(items) where Item: IdentifiableForEach(items.indices, id: \.self)High
2726ListsUse onDelete and onMoveStandard list editingonDelete for swipe to deleteCustom delete implementation.onDelete(perform: delete).onTapGesture for deleteLow
2827FormsUse Form for settingsGrouped input controlsForm for settings screensManual grouping for formsForm { Section { Toggle() } }VStack { Toggle() }Lowhttps://developer.apple.com/documentation/swiftui/form
2928FormsUse @FocusState for keyboardManage keyboard focus@FocusState for text field focusManual first responder handling@FocusState private var isFocused: BoolUIKit first responderMediumhttps://developer.apple.com/documentation/swiftui/focusstate
3029FormsValidate input properlyShow validation feedbackReal-time validation feedbackSubmit without validationTextField with validation stateTextField without error handlingMedium
3130AsyncUse .task for async workAutomatic cancellation on view disappear.task for view lifecycle asynconAppear with Task.task { await loadData() }onAppear { Task { await loadData() } }Mediumhttps://developer.apple.com/documentation/swiftui/view/task(priority:_:)
3231AsyncHandle loading statesShow progress during async operationsProgressView during loadingEmpty view during loadif isLoading { ProgressView() }No loading indicatorMedium
3332AsyncUse @MainActor for UI updatesEnsure UI updates on main thread@MainActor on view modelsManual DispatchQueue.main@MainActor class ViewModelDispatchQueue.main.asyncMedium
3433AnimationUse withAnimationAnimate state changeswithAnimation for state transitionsNo animation for state changeswithAnimation { isExpanded.toggle() }isExpanded.toggle()Lowhttps://developer.apple.com/documentation/swiftui/withanimation(_:_:)
3534AnimationUse .animation modifierApply animations to views.animation(.spring()) on viewManual animation timing.animation(.easeInOut)CABasicAnimation equivalentLow
3635AnimationRespect reduced motionCheck accessibility settingsCheck accessibilityReduceMotionIgnore motion preferences@Environment(\.accessibilityReduceMotion)Always animate regardlessHigh
3736PreviewUse #Preview macro (Xcode 15+)Modern preview syntax#Preview for view previewsPreviewProvider protocol#Preview { ContentView() }struct ContentView_Previews: PreviewProviderLow
3837PreviewCreate multiple previewsTest different states and devicesMultiple previews for statesSingle preview only#Preview("Light") { } #Preview("Dark") { }Single preview configurationLow
3938PreviewUse preview dataDedicated preview mock dataStatic preview dataProduction data in previewsItem.preview for previewFetch real data in previewLow
4039PerformanceAvoid expensive body computationsBody should be fast to computePrecompute in view modelHeavy computation in bodyvm.computedValue in bodyComplex calculation in bodyHigh
4140PerformanceUse Equatable viewsSkip unnecessary view updatesEquatable for complex viewsDefault equality for all viewsstruct MyView: View EquatableNo Equatable conformanceMedium
4241PerformanceProfile with InstrumentsMeasure before optimizingUse SwiftUI InstrumentsGuess at performance issuesProfile with InstrumentsOptimize without measuringMedium
4342AccessibilityAdd accessibility labelsDescribe UI elements.accessibilityLabel for contextMissing labels.accessibilityLabel("Close button")Button without labelHighhttps://developer.apple.com/documentation/swiftui/view/accessibilitylabel(_:)-1d7jv
4443AccessibilitySupport Dynamic TypeRespect text size preferencesScalable fonts and layoutsFixed font sizes.font(.body) with Dynamic Type.font(.system(size: 16))High
4544AccessibilityUse semantic viewsProper accessibility traitsCorrect accessibilityTraitsWrong semantic meaningButton for actions Image for displayImage that acts like buttonMedium
4645TestingUse ViewInspector for testingThird-party view testingViewInspector for unit testsUI tests onlyViewInspector assertionsOnly XCUITestMedium
4746TestingTest view modelsUnit test business logicXCTest for view modelSkip view model testingTest ViewModel methodsNo unit testsMedium
4847TestingUse preview as visual testPreviews catch visual regressionsMultiple preview configurationsNo visual verificationPreview different statesSingle preview onlyLow
4948ArchitectureUse MVVM patternSeparate view and logicViewModel for business logicLogic in ViewObservableObject ViewModel@State for complex logicMedium
5049ArchitectureKeep views dumbViews display view model stateView reads from ViewModelBusiness logic in Viewview.items from vm.itemsComplex filtering in ViewMedium
5150ArchitectureUse dependency injectionInject dependencies for testingInitialize with dependenciesHard-coded dependenciesinit(service: ServiceProtocol)let service = RealService()Medium