After knowing about Cursor, I am exploring ways to avoid context switching between Xcode and Cursor. While compile-time errors is still something that I am figuring out, I setup Cursor to build and run iOS apps directly on the simulator, without needing to open Xcode.

Finding the Right Extension

I think I tried every Swift and iOS-related extension available in Cursor's marketplace. While they were helpful, none solved the build-and-run problem.

On X, the creator of Sweetpad, an extension for Cursor, mentioned about it in a comment. Initially, I had an issue with the extension, but after reporting it on GitHub, Yevhenii quickly resolved them.

No affliation, but it is something I recommend:

SweetPad (iOS/Swift development) - Visual Studio Marketplace
Extension for Visual Studio Code - Develop Swift/iOS projects in VS Code

Installing Sweetpad is straightforward, so I will spare the details on it. What I wanted was the keyboard shorcuts. I chose the target simulator (iPhone 15 Pro) and default Xcode scheme to build as Meshing.

Keyboard Shortcuts

For building and running, I used Control+Command+R (as Command+R had too many conflicts):

{
  "key": "ctrl+cmd+r",
  "command": "sweetpad.build.launch"
}

For building, I set it to Command+B, similar to Xcode:

{
  "key": "cmd+b",
  "command": "sweetpad.build.build"
}

These allow me to build and run the app, launching the given simulator directly from Cursor.

Hot Reload

To avoid relying on Xcode's previews, I use the Inject framework:

GitHub - krzysztofzablocki/Inject at rudrank.com
Hot Reloading for Swift applications! . Contribute to krzysztofzablocki/Inject development by creating an account on GitHub.

I have set up rules to inject the necessary code into my views automatically. You can read about it here:

Exploring Cursor: Rules for AI Using cursorrules
Boost SwiftUI development with Cursor and custom .cursorrules. Leverage Claude Sonnet 3.5 for up-to-date iOS 17 APIs, async/await implementation, and hot reloading with Inject. Learn how to set up .cursorrules for streamlined development and reduce coding friction.

Whenever I make changes, they instantly appear in the simulator without needing to rebuild the entire app.

Moving Forward

While it took a bit of effort to set up, the resulting workflow is worth it. I can now write code, build, run, and see changes all within Cursor while using Claude Sonnet 3.5. The main goal of reducing the friction of switching IDEs and between browser is working out well.

I have realised it is better to learn more about working with LLM powered IDEs to be more productive and adapt to the new world.

Happy cursoring!

String Catalog

String Catalog - App Localization on Autopilot

Push to GitHub, and we'll automatically localize your app for 40+ languages, saving you hours of manual work.

Tagged in: