JUNPING

Setting Up an iOS Development Environment in Cursor/VSCode

Xcode's notorious difficulty is well-known, and if you want to develop iOS applications directly in Cursor or VSCode, you'll find they don't natively support it. However, by following these steps, you can configure a complete environment with code suggestions, compilation, debugging, AI assistance, and other features.

The configuration process for Cursor and VSCode is nearly identical. We'll use Cursor as our example here.

Many developers who've tried this setup may have encountered errors where the editor flags self-written methods, indicating it cannot find them (Cannot find '***' in scope SourceKit). We'll address this issue directly in step 3.

1. Install the Swift and CodeLLDB extensions

The Swift extension provides basic support for the Swift language, while CodeLLDB enables debugging functionality.

2. Install the SweetPad extension

This extension allows you to configure code formatting, debugging, and other features in the editor. Take some time to explore its configuration options.

3. Configure Swift LSP to correctly recognize project code

After completing the above steps, you may notice that the editor still reports errors, with many instances of: Cannot find '***' in scope SourceKit.

This occurs because Swift's sourcekit-lsp hasn't indexed your project files, so the editor can't locate your methods. There are two ways to resolve this issue:

[Recommended] Method 1: Configure the project using Xcode-Build-Server

First, install Xcode-Build-Server:

brew install xcode-build-server

Then, in your project's root directory, run:

xcode-build-server config -workspace *.xcworkspace -scheme <XXX>
xcode-build-server config -project *.xcodeproj -scheme <XXX>

For example, if you're using exampleProject.xcodeproj:

xcode-build-server config -project exampleProject.xcodeproj -scheme exampleProject

Restart the editor for the changes to take effect.

Method 2: Configure the project using Package.swift

Create a Package.swift file in your project's root directory with the following content:

// swift-tools-version:5.9
import PackageDescription
let packageName = "YourProjectName" // Replace with your actual project name
let package = Package(
name: packageName,
platforms: [
.iOS(.v16) // Adjust to your target iOS version
],
products: [
.library(
name: packageName,
targets: [packageName]
),
],
targets: [
.target(
name: packageName,
path: packageName
)
]
)

Restart the editor for the changes to take effect.

You're now ready to enjoy a modern iOS development experience! If you have any questions, please don't hesitate to leave a comment.