I am slowly writing a book on Exploring! Check it out, and be the first one to read it!

Exploring Cursor AI Editor for iOS Development
This book offers a practical guide to use the AI-powered code editor, Cursor, and incorporate it in your daily Swift and SwiftUI workflows.What you will learn:Hot Reloading for Faster Iteration: Set up hot reloading with Cursor and Inject to see code changes reflected instantly in the simulator, speeding up your development process.AI-Assisted Coding in Swift: Utilize Cursor’s AI capabilities for code generation, refactoring, and creating UI elements directly from simple prompts and Cursor rules.Understand Cursor’s Composer: Explore Composer’s advanced functionalities for managing multi-file edits, refining UI using screenshots, integrating external documentation and browsing the web.Debugging Strategies: Troubleshoot and resolve common issues that may arise when using Cursor and AI-generated code.This book is for:iOS developers looking for ways to improve their workflow with AI assistance and reduce friction.

Working with Cursor is amazing. I am using Xcode since 2018, and barely used any other IDE so Cursor is the second IDE that I have spent so much time with.

To make my life easier, I started using the .cursorrules in Cursor. You can put rules that are added for all the chats and every time you Command+K, making it exactly what I need for my SwiftUI projects.

Why Custom Rules?

  • Cursor uses Claude Sonnet 3.5 trained till April 2024, which knows about iOS 17 APIs. I can have Cursor always use NavigationStack instead of NavigationView, and similar APIs making my code upto date.
  • No callback hell please. No completion handlers. The rules ensure I am using async/await to deal with Swift 6 migration hell as well.
  • I use Inject to update simulator without relying on previews so that I barely have to open Xcode, and minimise context switching between two IDEs.

Setting up your cursorrules

Create a new file in the root directory with the extension .cursorrules. In that file, add your prompt. Here is a simple template to get you started:

You are an AI assistant specialized in SwiftUI development. Your role is to help developers write clean, efficient, and modern SwiftUI code. Follow these guidelines in all your responses:

## General Guidelines
1. Use the latest SwiftUI APIs and features whenever possible.
2. Implement async/await for asynchronous operations.
3. Write clean, readable, and well-structured code.

## Hot Reloading Setup
For all SwiftUI views, include the following to enable hot reloading:
1. Import the Inject framework.
2. Add the @ObserveInjection property wrapper to the view.
3. Use the .enableInjection() modifier in the main body of the view.

## Code Structure
When creating or modifying SwiftUI views, always use this structure if the view does not have it already:

```swift
import SwiftUI
import Inject

struct YourViewName: View {
    @ObserveInjection var inject
    
    // Other properties here
    
    var body: some View {
        // Your view content here
            .enableInjection()
    }
}

More SwiftUI Rules

While my rules focus mostly on getting it to work with hot reloading, you can take it a step further.

Here are Swift Cursor Rules by Ray and Lou:

Swift Cursor Rules
Cursorrules for developing with Swift and SwiftUI

These help write efficient, maintainable SwiftUI apps by emphasizing proper state management, performance optimization, and adherence to SwiftUI-specific patterns.

Moving Forward

With these rules in place, it is easier to update code with Cursor. You can always tweak these rules as your needs change to make the most out of it.

I have realised that Cursor has reduced the friction of using Claude on browser, and manually updating the code. To ship a ton, I need to spend less time coding, and more time apping instead.

For now, happy cursoring!

Astro Affiliate.

Astro (Affiliate)

Find the right keywords for your app and climb the App Store rankings. Improve your app visibility and increase your revenue with Astro. The first App Store Optimization tool designed for indie developers!

Tagged in: