Swift Cursor Rules
Learn about cursor rules specific to Swift and iOS/macOS development.
Swift-Specific Rules
Cursor rules in Swift provide intelligent navigation and manipulation capabilities designed specifically for Swift and iOS/macOS development. These rules enhance your productivity when working with Swift's modern features, SwiftUI, and the Combine framework.
Code Navigation
- Navigate between class, struct, and protocol declarations
- Jump through property wrappers and property observers
- Quick access to SwiftUI view modifiers
- Smart navigation through closure expressions
Smart Selection
- Select optional chaining and nil-coalescing operators
- Expand selection to include property wrappers
- Smart type inference and protocol conformance selection
- SwiftUI view hierarchy selection
Code Manipulation
- Quick property wrapper insertion
- Automated optional handling
- SwiftUI modifier management
- Protocol conformance assistance
Best Practices
- Use type-safe navigation patterns
- Leverage Swift's strong type system
- Utilize SwiftUI-aware cursor movements
Examples
// Navigate between type declarations
protocol ViewModelProtocol {
associatedtype Model
var model: Model { get set }
}
@MainActor
class ContentViewModel: ViewModelProtocol {
@Published var model: String
init(model: String = "") {
self.model = model
}
}
// Smart selection of SwiftUI views
struct ContentView: View {
@StateObject private var viewModel = ContentViewModel()
var body: some View {
NavigationStack {
List {
ForEach(items) { item in
Text(item.title)
.font(.headline)
.foregroundColor(.primary)
}
}
.navigationTitle("Items")
}
}
}
Configuration
Customize Swift-specific cursor rules in your settings:
{
"swift.cursorRules": {
"typeNavigation": true,
"swiftUIAware": true,
"propertyWrapperHandling": true
}
}