场景定位
把过大的 SwiftUI screen 拆成小 subviews,同时保持行为不变。 本页把官方 use case 的章节、工具、起步提示词和检查点整理成中文执行流程,便于直接对照落地。
- 难度
- 高级
- 时间跨度
- 约 30-60 分钟
适合用于
- 需要把「把过大的 SwiftUI screen 拆成小 subviews,同时保持行为不变。」做成可复用流程的团队,且来源分散在 Build iOS Apps 等工具中
- 希望 ChatGPT 或 Codex 保留来源、检查点和可审阅输出的使用者
- 需要把「重构 SwiftUI 页面」从一次性对话变成可复查工作流的场景
Skills & Plugins
相关工具
Starter Prompt
起步提示词
Use the Build iOS Apps plugin and its SwiftUI view refactor skill to clean up [NameOfScreen.swift] without changing what the screen does or how it looks.
Constraints:
- Preserve behavior, layout, navigation, and business logic unless you find a bug that must be called out separately.
- Default to MV, not MVVM. Prefer `@State`, `@Environment`, `@Query`, `.task`, `.task(id:)`, and `onChange` before introducing a new view model, and only keep a view model if this feature clearly needs one.
- Reorder the view so stored properties, computed state, `init`, `body`, view helpers, and helper methods are easy to scan top to bottom.
- Extract meaningful sections into dedicated `View` types with small explicit inputs, `@Binding`s, and callbacks. Do not replace one giant `body` with a pile of large computed `some View` properties.
- Move non-trivial button actions and side effects out of `body` into small methods, and move real business logic into services or models.
- Keep the root view tree stable. Avoid top-level `if/else` branches that swap entirely different screens when localized conditional sections or modifiers are enough.
- Fix Observation ownership while refactoring: use `@State` for root `@Observable` models on iOS 17+, and avoid optional or delayed-initialized view models unless the UI genuinely needs that state shape.
- After each extraction, run the smallest useful build or test check that proves the screen still behaves the same.
Deliver:
- the refactored screen and any extracted subviews
- a short explanation of the new subview boundaries and data flow
- any places where you intentionally kept a view model and why
- the validation checks you ran to prove behavior stayed intact 在 ChatGPT 中尝试 Refactor one screen without changing what it does
这一节对应官方流程中的「Refactor one screen without changing what it does」。落地时围绕「重构 SwiftUI 页面」把目标、输入、执行步骤和验证证据保持在同一条工作流里。
操作要点:先把本节需要的来源材料、权限和上下文补齐,并关注 Codex、SwiftUI 等相关来源或工具;缺失内容要明确标记,不要让 ChatGPT 或 Codex 隐式猜测。
操作要点:把已确认的上下文转成「重构 SwiftUI 页面」所需的可审阅草稿或交付物,并关注 iOS、SwiftUI 等相关来源或工具,并保留后续修改入口。
应该让 Codex 做什么
这一节对应官方流程中的「What to ask Codex to do」。落地时围绕「重构 SwiftUI 页面」把目标、输入、执行步骤和验证证据保持在同一条工作流里。
操作要点:先把本节需要的来源材料、权限和上下文补齐,并关注 Codex 等相关来源或工具;缺失内容要明确标记,不要让 ChatGPT 或 Codex 隐式猜测。
- 先把本节需要的来源材料、权限和上下文补齐;缺失内容要明确标记,不要让 ChatGPT 或 Codex 隐式猜测。
- 围绕「What to ask Codex to do」推进「重构 SwiftUI 页面」时,保持目标、输入、执行步骤和验证结果一致。
- 把已确认的上下文转成「重构 SwiftUI 页面」所需的可审阅草稿或交付物,并保留后续修改入口。
- 围绕「What to ask Codex to do」推进「重构 SwiftUI 页面」时,保持目标、输入、执行步骤和验证结果一致。
- 围绕「What to ask Codex to do」推进「重构 SwiftUI 页面」时,保持目标、输入、执行步骤和验证结果一致。
- 把风险、决策、负责人和下一步动作分开记录,并关注 iOS 等相关来源或工具,并说明每个判断来自哪些材料。
Ask for a small validation loop
这一节对应官方流程中的「Ask for a small validation loop」。落地时围绕「重构 SwiftUI 页面」把目标、输入、执行步骤和验证证据保持在同一条工作流里。
操作要点:把已确认的上下文转成「重构 SwiftUI 页面」所需的可审阅草稿或交付物,并关注 Codex 等相关来源或工具,并保留后续修改入口。
实用提示
这一节对应官方流程中的「Practical tips」。落地时围绕「重构 SwiftUI 页面」把目标、输入、执行步骤和验证证据保持在同一条工作流里。
小节:Split first, then debate architecture。
操作要点:在继续执行前检查来源、假设、受众、权限和输出质量,并关注 Codex 等相关来源或工具;不确定内容应进入待确认列表。
小节:Pass the smallest possible interface into each subview。
操作要点:在继续执行前检查来源、假设、受众、权限和输出质量;不确定内容应进入待确认列表。
小节:让 Codex call out intentional non-变更。
操作要点:在继续执行前检查来源、假设、受众、权限和输出质量,并关注 Codex 等相关来源或工具;不确定内容应进入待确认列表。
Prompt Library
建议提示词
先界定范围
For Refactor SwiftUI screens, first inspect the available sources and propose the smallest useful scope. Name the inputs, outputs, validation steps, permissions, and anything that needs approval before action. 交付前复核
Review the result for Refactor SwiftUI screens. Check source coverage, assumptions, unresolved questions, and the evidence that proves the output is ready to use. 技术栈
Large screens usually get easier to maintain when Codex simplifies the view tree and state flow before introducing another view model layer.
The plugin's SwiftUI view refactor skill gives Codex clear rules for extraction, Observation, and side-effect cleanup while preserving behavior.
Small 构建 or simulator checks after each extraction make it easier to trust a behavior-preserving refactor than a one-shot rewrite.