Cursor Rules for iOS Development
Cursor Guide for iOS Engineers (Part 2)
Rules for AI
Cursor provides a "Rules for AI" feature that allows you to finely tune how the AI operates within your codebase. Well-written rules help maintain code quality and can adjust AI responses with much greater precision. By using Rules, you can customize Cursor's output on a per-project basis or across the entire editor. Think of it as a system prompt for the LLM. You can define its role, personality, and area of expertise. You set the rules for what it should and shouldn't do, and you can provide context. It effectively restricts the AI's responses to a specific domain, task, context, or style.
Project-Level Rules
In Cursor, you can write these in the .cursor/rules directory. You can add a description and specify a pattern for the files the rule should apply to. I'll share the rules I use below. Using @file, you can reference other files and chain multiple rules together. You can explicitly state when the rule should be used.
You can create a new rule by using Cmd + Shift + P > New Cursor Rule. Let's say we're adding rules for SwiftUI-based app development. Below are the rules I'm currently using.
from https://www.rayfernando.ai/swift-cursor-rules
Writing Commit Messages Using Cursor
Now that we've added the rules files, let's write a commit message using Cursor. Press Command + Control + G to open the Source Control panel. Click the ✨ button on the right side of the text box to generate a commit message. It writes the commit message by referencing staged files and your Git history, taking both current changes and past history into account. If your commit messages follow a specific convention, it will write them using that pattern. I heard the commit message generation currently only supports English. Of course, you could also use the Chat feature to write commit messages in other languages. You can check out the details here.
My Impressions So Far
I haven't dived deeply into a wide variety of Cursor rules just yet, but since I started using them, the rate of hallucinations or generating buggy code has noticeably dropped. The Cursor agent used to occasionally generate duplicate files, but after applying rules, it hasn't repeated that mistake. Next time, I'll share some more detailed know-how.