SwiftUI 代理技能:使用人工智能构建更好的视图
SwiftUI Agent Skill: Build Better Views with AI

原始链接: https://www.avanderlee.com/ai-development/swiftui-agent-skill-build-better-views-with-ai/

## SwiftUI Agent Skill:提升你的代码水平 一个新的开源SwiftUI Agent Skill可用,帮助开发者构建更好的视图并重构现有代码,显著提高代码质量。该技能可在GitHub上找到(AvdLee/SwiftUI-Agent-Skill),它为代理提供了超越基础SwiftUI语法的专业知识,解决了诸如不正确的`onChange()`用法等常见问题。 该技能包含详细的参考资料,涵盖图像优化、布局最佳实践、性能模式、现代API和状态管理等领域。它会主动分析代码,识别嵌套滚动冲突和冗余更新等问题,并提供具体的改进建议。 除了修复现有代码外,该技能还在代理*创建*视图时主动增强视图,从而减少未来的技术债务。虽然代理技能的发现仍在发展中,但该工具有望成为SwiftUI开发中不可或缺的工具。 该项目欢迎贡献——鼓励开发者提交拉取请求,并学习如何通过详细的指南构建和测试代理技能。最终,SwiftUI Agent Skill是任何开发者工具包中的强大补充,可以带来更简洁、更高效、更易于维护的SwiftUI代码。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 SwiftUI Agent 技能:使用 AI 构建更好的视图 (avanderlee.com) 31 分,由 skreep 1 天前发布 | 隐藏 | 过去 | 收藏 | 1 条评论 帮助 cadamsdotcom 1 天前 [–] 这些有多少可以由代理编写成代码检查?让它遍历 AST,查找反模式——最终更像一个自定义的 linter,无需浪费 token 让可怜的模型主观分析其决策。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

A SwiftUI Agent Skill that helps you build better views or refactor existing ones. It’s the reality we’re in today, and I honestly can’t live without it anymore myself. Several skills helped me improve the code quality produced by agents, and I’m happy to introduce you to a new open-source skill for SwiftUI.

Before reading this article, I highly recommend reading Agent Skills explained: Replacing AGENTS.md with reusable AI knowledge. It’s the foundation of what you need to know about this feature. Additionally, you can read a brief background on this new skill in How I Stopped Resisting AI and Started Teaching It, written by Omar Elsayed, with whom I built this skill.

Adding SwiftUI Expertise to your Agents

If you’ve been building with agents, I’m sure you’ve been updating your AGENTS.md file with all kinds of fixes for SwiftUI. One of the most common additions I’ve seen is this one:

Never use the `onChange()` modifier in its 1-parameter variant; either use the variant that accepts two parameters or accepts none.

If you know, you know, but it’s annoying when agents make the same mistake over and over again. I’ve been updating my agents file too, but I’m now prompting this instead:

The SwiftUI Agent skill is available on GitHub at AvdLee/SwiftUI-Agent-Skill. It contains a detailed SKILL.md file and several specific references:

swiftui-expert-skill/
  SKILL.md
  references/
    image-optimization.md - AsyncImage usage, downsampling, caching
    layout-best-practices.md - Layout patterns and GeometryReader alternatives
    liquid-glass.md - iOS 26+ glass effects and fallback patterns
    list-patterns.md - ForEach identity and list performance
    modern-apis.md - Deprecated API replacements
    performance-patterns.md - Hot-path optimizations and update control
    scroll-patterns.md - ScrollViewReader and programmatic scrolling
    sheet-navigation-patterns.md - Sheets and type-safe navigation
    state-management.md - Property wrapper selection and data flow
    text-formatting.md - Modern Text formatting and string utilities
    view-structure.md - View extraction and composition patterns

(I recommend checking the repo for an up to date overview)

What’s interesting is that this leads to a detailed response while planning together with this skill. For the above prompt, the results showed various improvements. Here’s an example of view structure that could be improved:

  • Nested scrollingBuildInsightsPageView wraps BuildInsightsView in a ScrollView, but BuildInsightsView already contains its own ScrollView, which can cause awkward scrolling/gesture behavior and layout work.

But it’s also great at analyzing performance patterns:

  • Selection/view-model synchronization is duplicated and easy to get into redundant updates: there are multiple onAppear/onChange handlers that all set currentSelectedApp and/or viewModel.

It totally depends on what you are building and how good your views already are. However, if you’ve been developing with agents for a while now, you’ve probably created views that can be improved already.

FREE 5-Day Email Course: The Swift Concurrency Playbook

A FREE 5-day email course revealing the 5 biggest mistakes iOS developers make with with async/await that lead to App Store rejections And migration projects taking months instead of days (even if you've been writing Swift for years)

Reducing tech debt using the SwiftUI Agent Skill

At the same time, your future views built with agents can be better from the start. Agents are smart enough to reference the skill when needed, so chances are high that your initial versions of SwiftUI Views will already be improved using this Agent Skill. It’s important to note that agents aren’t always able to find skills yet, but it’s only a matter of time before they do.

We’re open to contributions!

If you have been developing intensively with agents already, you might have created your own set of agent instructions. We’ve already merged several pull requests from developers like yourself, and we would love to receive more. Feel free to open a PR, and make sure to read our detailed contribution guidelines. Not because we’re strict, but because it will teach you how to built and test agent skills along the way!

Conclusion

The SwiftUI Agent Skill already impacts the code I create with agents and I’m sure it will make your code better as well. The skill is in active development, continously evolving, but I can’t imagine writing code without it anymore. Even views I’ve written completely myself get improved, which is just a golden path to reducing tech debt.

If you want to improve your AI development knowledge, even more, check out the AI Development Category page. Feel free to contact me or tweet me on Twitter if you have any additional tips or feedback.

Thanks!

 

联系我们 contact @ memedata.com