By djs66256
Build iOS pages with DDComponent's MVP architecture using Presenter tree patterns, and automatically review code for type correctness, state design, lifecycle usage, and logical cohesion.
基于 MVP 模式的 iOS 页面拆分框架。将复杂页面拆分为独立、可复用、可插拔的 Presenter 组件。
| 问题 | DDComponent 的解法 |
|---|---|
| 多人修改同一文件导致冲突 | 每个功能拆分为独立的 Presenter,互不干扰 |
| 功能边界模糊,无人对质量负责 | Presenter 是明确的逻辑边界,职责清晰 |
| 同一功能不同 UI(如 Resso vs TTM) | P-Tree 与 V-Tree 分离,逻辑复用,UI 可替换 |
| 功能需要动态插拔 | 通过 install DSL 按需装配 Presenter 和 Service |
P-Tree (Presenter 树) V-Tree (View 树)
┌─────────────────┐ ┌─────────────────┐
│ RootPresenter │ - - - - │ RootView │
│ ├ LikePresenter │ - - - - │ ├ LikeButton │
│ ├ SharePresenter│ - - - - │ ├ ShareButton │
│ └ CommentPresenter│ - - - │ └ CommentList │
└─────────────────┘ └─────────────────┘
DDComponent 借鉴 React/SwiftUI 的思想,所有 UI 更新必须通过 setState 统一入口,由 UpdatePipeline 批量执行:
数据变更 → setState { ... } → Pipeline 调度 → onUpdate(view:context:) → UI 更新
// 1. View 协议(不是 UIView)
protocol LikeViewProtocol: AnyObject {
var isLiked: Bool { get set }
var likeCount: Int { get set }
var onLikeTapped: (() -> Void)? { get set }
}
// 2. Presenter(业务逻辑)
class LikePresenter: ViewPresenter<LikeViewProtocol> {
var isLiked = false { didSet { setState {} } }
func toggleLike() {
getService(LikeService.self)?.toggleLike { [weak self] result in
self?.isLiked = result
}
}
override func onBindView(_ view: LikeViewProtocol) {
view.onLikeTapped = { [weak self] in self?.toggleLike() }
}
override func onUpdate(view: LikeViewProtocol, context: ViewUpdateContext) {
view.isLiked = isLiked
}
}
// 3. 装配
class MyViewController: PageViewController<MyRootView, MyRootPresenter> {
@PageInstallerBuilder override var pageInstallers: PageInstaller {
ServiceInstaller(LikeService.self, { LikeServiceImpl() })
}
}
pod 'DDComponent'
# 可选:@PresenterState 宏
pod 'DDComponent/Macros'
| 你想... | 看这个 |
|---|---|
| 理解框架设计思想 | 架构设计 |
| 创建页面/列表/功能 | 使用指南 |
| 开发列表 Cell | 复用 Presenter |
| 使用 Hooks 风格 API | use* API |
| 简化状态声明 | @PresenterState 宏 |
| Swift 6 适配 | Swift 6 并发模式 |
| 看示例代码 | Demo 索引 |
文档索引:docs/README.md
框架包含 122 个单元测试,覆盖所有核心能力。测试位于 Example/Tests/。
cd Example
xcodebuild test -project DDComponent.xcodeproj -scheme DDComponent-Example -destination 'platform=iOS Simulator,name=iPhone 17'
DDComponent is available under the MIT license. See the LICENSE file for more info.
Uses power tools
Uses Bash, Write, or Edit tools
Based on adoption, maintenance, documentation, and repository signals. Not a security audit or endorsement.
npx claudepluginhub djs66256/ddcomponent --plugin ddcomponentiOS and Swift development with SwiftUI views and models
Agents and skills for Swift app development on iOS.
Swift iOS architecture guidance and playbooks for MVVM, MVI, TCA, Clean Architecture, VIPER, MVP, Coordinator, and Reactive patterns. Use when designing, implementing, refactoring, or reviewing the architecture of a SwiftUI or UIKit feature, module, or codebase.
Expert SwiftUI guidance for state management, view composition, performance, and iOS 26+ Liquid Glass adoption.
Swift, SwiftUI, SwiftData, iOS animation design/implementation/review, and framework code review (HealthKit, CloudKit, WidgetKit, watchOS, App Intents). Pairs with beagle-core for full workflow.
Ultra-compressed communication mode. Cuts 65% of output tokens (measured) while keeping full technical accuracy by speaking like a caveman.