How to build an iOS app in just a few minutes with AI

即使到了2025年,产品设计和开发之间仍存在差距:设计软件里的效果往往和最终产品不一致。这主要源于设计和开发团队之间的沟通。虽然让一个人同时负责设计和开发可以解决这个问题,但大多数UI设计师不会编程。

比如Cursor AI、Lovable和Bolt。这些工具可以用AI来创建完整的产品。随着这些AI工具的发展,出现了一种新型的专业人员—氛围编程师 *vibe coders *。他们虽然不是专业程序员,但懂得如何用AI来生成代码。

在这篇文章中,我将向你展示如何使用Cursor AI来开发一个简单的iOS股票查看应用。我们会一步步学习如何有效地使用AI工具来帮助开发,并且也会讨论这种方法的优点和局限性。

使用AI构建iOS应用所需的准备

你需要准备以下3样东西:

  1. *Macbook或iMac电脑*
  2. *Xcode**。*这是用于macOS的集成开发环境,用于开发macOS、iOS和iPadOS软件。
  3. *Cursor AI**。*Cursor AI是一个带有AI代理的开发环境,用于生成代码。

第一步:在Xcode中创建新项目

在Xcode中你只需要做一件事,就是创建新项目。导航到iOS选项卡并点击应用程序:

在Xcode中选择项目模板:

点击"下一步"后,你需要为项目命名并选择存储位置。

在Xcode中命名项目:

Xcode创建的项目将是最基础的它只包含必要的文件和一个屏幕(iOS使用视图的概念,因此从技术上讲,它将是一个带有Hello World的ContentView视图)。确保Xcode可以构建项目,并且可以在预览中看到。

创建项目并确保Xcode可以构建它后,你就可以转到Cursor AI来生成代码了。

第二步:在Cursor AI中打开iOS项目

当你在Cursor AI中打开项目后,你会看到你的工作环境。如果你之前使用过Visual Studio Code这样的IDE,Cursor AI的界面会让你感到很熟悉。基本上,它就是在VS Code的设计基础上增加了一层AI功能。

大多数时候,你会与3个面板进行交互:

  1. 左侧面板是项目文件树
  2. 底部面板是终端

Cursor AI中打开的左侧和底部面板。

  1. 右侧面板是AI助手面板。

在Cursor AI中打开的所有三个面板。

所有神奇的事情都将发生在第三个面板 — AI助手面板中。我们将通过提示AI代理来生成代码。如你在我的示例中所见,我已经提供了一个构建股票价格应用的提示。一旦我点击发送,AI代理就会执行任务并为我生成代码。

第三步:充分利用Cursor AI

在发送第一个提示之前,你需要检查几个事项以充分利用Cursor AI。首先,确保添加*.cursorrules*文件,在其中提供Cursor在编写代码时应遵循的具体指令。由于我正在构建iOS应用,我将提供SwiftUI的相关指令。

SwiftUI项目的.Cursorrules文件。

如果你在想这个文件里应该写什么,我这里有几个解决方案 — 你可以写一些你认为对项目有意义的内容,或者使用Cursor社区编写的指令。寻找这类指令的好去处是Cursor.directory。只需在搜索栏中输入你想在项目中使用的技术,你就能找到适用于你项目的现成规则。

特定技术和语言的规则数据库。

另一件你需要做的事情是为你的设计特定领域提供开发者文档和最佳实践。你可以通过在Agent窗口中标记文档来实现这一点。就我而言,我已经标记了Apple Swift和Apple Design Tips文档(查看右上角)。

Tagging documents in Agent.

There are two ways you can add a new document. Either press *Add context*, choose *Docs* and click *Add new doc*.

Adding new docs to context.

Or click the *Gear* icon, navigate to the Features tab, and scroll down to Docs.

Adding new doc in Cursor Settings -> Features -> Docs section.

Finally, you need to add the docs to the context simply by clicking on the docs you want AI assistant to use when generating code.

Adding two docs to the context.

Step 4: Generating code with AI

Once you add project rules to Cursor and docs to context, it’s time to generate code using AI assistant. It is by far the most challenging part of the process because you need to clearly formulate what you want to build a why.

The prompt you submit to AI agent should:

  • Clearly explain what you want to build (what your app is all about);
  • What screens will that app have and how they will be connected;
  • Provide information about content and functionality individual screens should have.

You need to understand that there is a low chance that AI will build a perfect app from the first attempt. So be ready to iterate and refine both your initial prompt and follow-up prompts.

Prompt I’ve used to generate stock price app for iOS.

Once you submit the prompt, Cursor will start to generate code for you. The great about Cursor is that you, as a user, have full control over changes. You can either accept or reject individual changes provided by the Cursor, and only when you accept them will the Cursor change actual files.

Cursor AI suggests code changes based on your prompt.

You can navigate back to Xcode to see the results that Cursor generated.

StockPrice app generated by Cursor AI.

Step 5: App refinement and iterative design with AI

As I’ve mentioned before, there is a low possibility that you will get a final solution right from the first attempt. So you will need to provide additional prompts to Cursor to refine the app. Potential areas of refinement can be — improving business logic (adding/removing content or functionality) and visual refinement. For example, below is my attempt to make the app look visually pretty. You can see that I use a simple prompt, “*Make both StockListView and StockDetailsView look visually nice*,” and Cursor clearly understands my intention.

Refining the app using AI.

If you navigate back to the Xcode, you will see the changes that Cursor introduces makes the app look visually more polished.

Refined visual appearance of the app.

FAQ about Cursor AI & vibe coding in general

*Q: Can I use Cursor AI to build an entire app without learning coding skills*

A: My honest answer is No, at least not at this moment. Cursor is a very good co-creator, but you still need to drive the bus and validate the quality of the code generated by Cursor.

*Q: Can I use Cursor to build complex apps with sophisticated business logic?*

A: You can try, but it will likely require a lot of back-and-forth between Cursor AI and Xcode. You will need to refine both your prompts and be ready to dive into code to refine details. Based on my experience, Cursor is good for building simple products (like the StockPrice app I’ve shared here) and as a contextual helper when you have a particular task at hand (i.e., want to refine a design of a particular screen in your product).

*Q: Do you think skills in using Cursor AI or similar tools will be must-have for UI designers?*

A: Yes, I do. Vibe coding will be an important part of the UI designer job in the future; we will practice vibe coding when building initial designs, and this will help bridge the gap between design and development.