Brief overview of Cursor and why AI-powered PR reviews matter.
Three Modes
PR Review with Cursor Rules - Local, Interactive and Yolo Modes
What it is: Use the swift-review.sh script for a lightweight, offline PR review.
Ideal for: Developers who prefer local environments and quick checks.
Analyze the uncommitted Swift Changes and provide a report
Based on our rules and tools (script), Cursor has the ability to identify the critical issues in terms of memory management and swift convention.
Code Analysis Results
Critical Memory management issues are related to retain references will cause memory leak, Force Unwrapping, force casting, retain cycles in Closures (should use [weak self]).
Critical Memory Management issues
Apple has introduced Swift Testing framework and it is best practice to use the same. Currently, Swift testing support Unit testing and for UI Testing and Performance - we should stay with XCTest framework.
To learn more on this, check out → Swift Testing
Swift Testing Violates
AS discussed earlier, memory leaks, retain cycles and force unwrapping are said to be potential issues.
Actionable Fixes
Our local mode code review has recommended to not to commit the changes since it has critical issue and iOS issues and other violations.
Commit Recommendation
Priority 1: Fix Critical Memory Management Issues
We have Cursor rules for memory management.
Fix Suggestion - Priority 1
Potential File write Errors
Fix Suggestion - Potential File write errors
Force Unwrapping and Casting
Fix Suggestion - Force Unwrapping and Casting
Retain Cycle
Fix Suggestion - Use [weak self] to prevent retain cycle
Swift Testing over XCTest Framework
Fix Suggestion - Replace XCTest with Swift Testing
For UI Testing - Use XCTest Framework
Fix Suggestion - Replace XCTest with Swift Testing
Remove SwiftUI from ViewModel
Fix Suggestion - Remove SwiftUI framework from ViewModel
The first step is to disable the auto-run mode to allow Agent to run tools in an interactive mode like asking for confirmation.
Cursor → Settings → Cursor Settings → Features → Uncheck Enable auto-run mode
Cursor Settings
Setting PR Review System
Review PR
The first step is to enable the auto-run mode to allow Agent to run tools in an Yolo mode like without asking for confirmation.
Cursor → Settings → Cursor Settings → Features → Check Enable auto-run mode
Alert Window
Be cautious!
Potential prompt injection risks from external sources. If you are sure about the process, then you can turn on the Auto-run mode effectively.
Enable auto-run mode
Create new PR
PR Review
PR Review System Setup Complete
Based on the comprehensive review of PR #7, Cursor identified several critical issues that need to be addressed using rules and tools. Here's the review in the required JSON format:
{
"reviews": [
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 3,
"reviewComment": "**Global Variables**: Avoid global variables like `var g = \"\"` as they create mutable global state, making the code harder to test and reason about. Consider using instance properties or dependency injection instead."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 35,
"reviewComment": "**Force Unwrapping Safety**: Force unwrapping `text!` is unsafe and can crash the app. Use optional binding: `guard let t = text else { return \"\" }` or nil coalescing operator `text ?? \"\"`."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 36,
"reviewComment": "**Force Unwrapping Safety**: Force unwrapping `t.first!` can crash if the string is empty. Use safe unwrapping: `guard let firstChar = t.first else { return \"\" }`."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 37,
"reviewComment": "**Force Unwrapping Safety**: Force unwrapping URL creation is dangerous. Use proper error handling: `guard let url = URL(string: \"https://example.com\") else { return \"Invalid URL\" }`."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 45,
"reviewComment": "**Force Casting Safety**: Force casting `response as! HTTPURLResponse` can crash. Use conditional casting: `guard let httpResponse = response as? HTTPURLResponse else { return }`."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 49,
"reviewComment": "**Force Try Safety**: Using `try!` is unsafe and can crash the app. Use proper error handling with `do-catch` blocks to handle potential JSON parsing errors gracefully."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 22,
"reviewComment": "**Memory Management**: Timer is created without proper cleanup strategy. The timer in `deinit` is commented out, which will cause a memory leak. Uncomment `timer?.invalidate()` or use weak references."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 75,
"reviewComment": "**Retain Cycle**: Using `self` directly in closure creates a retain cycle. Use `[weak self]` capture list: `DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in guard let self = self else { return }; self.temp = \"updated\" }`."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 80,
"reviewComment": "**Retain Cycle**: Another strong reference to `self` in closure. Use `[weak self]` to prevent memory leaks: `DispatchQueue.global().async { [weak self] in guard let self = self else { return }; self.count += 1 }`."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 105,
"reviewComment": "**Global State Mutation**: Accessing and mutating global variable `g` violates encapsulation and makes code unpredictable. Remove global state dependencies and use proper dependency injection or instance methods."
},
{
"filePath": "GitHubExplorer/ViewModels/UserSearchViewModel.swift",
"lineNumber": 9,
"reviewComment": "**Force Unwrapping in Property**: `errorMessage: String!` uses force unwrapping. Use optional type `String?` instead for safer error handling: `@Published var errorMessage: String?`."
},
{
"filePath": "GitHubExplorerUITests/GitHubExplorerUITests.swift",
"lineNumber": 8,
"reviewComment": "**Swift Testing Convention**: Use Swift Testing framework instead of XCTest. Replace `import XCTest` with `import Testing` and convert class to struct with `@Suite` annotation for consistency with project standards."
},
{
"filePath": "GitHubExplorerUITests/GitHubExplorerUITestsLaunchTests.swift",
"lineNumber": 8,
"reviewComment": "**Swift Testing Convention**: Use Swift Testing framework instead of XCTest. Replace `import XCTest` with `import Testing` and convert to `@Suite struct` to follow project testing standards."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 57,
"reviewComment": "**Force Try Safety**: `try!` for file writing can crash the app. Use proper error handling: `do { try \"Some data\".write(to: URL(fileURLWithPath: filePath), atomically: true, encoding: .utf8) } catch { print(\"Failed to write file: \\(error)\") }`."
},
{
"filePath": "GitHubExplorer/Utils/NetworkUtilities.swift",
"lineNumber": 123,
"reviewComment": "**Multiple Force Operations**: This function has multiple force unwrapping operations (`data!`, `try!`, `as!`) which make it extremely crash-prone. Implement proper error handling with guard statements and do-catch blocks."
}
]
}
Code Review Results in JSON format
So, let’s try posting review comment to the GitHub PR.
You must be wondering what is pr-comment
echo " review-pr <number> - Review any PR number"
echo " pr-comment <args> - Post individual comment"
echo " list-prs - List all open PRs"
From pr-review-aliases.fish file
pr-comment GitHubExplorer/Utils/NetworkUtilities.swift linenumber 3
pr-comment
Successfully posted review comment
Another try!
pr-comment GitHubExplorer/Utils/NetworkUtilities.swift 123
pr-comment
Post Review comment Line Number #123 to the GitHub PR
Successfully posted review comment
Local —> Quick local feedback
Interactive —> Team standards & rule enforcement
YOLO(auto-run mode) —> Fastest, hands-off reviews
SPONSOR
The Unique iOS Swift Conference in the UK
SwiftLeeds is a premier iOS conference taking place on October 7-8 this year. If you’re looking to stay updated on the latest trends in iOS development and connect with like-minded professionals, this event is a must-attend! Don’t miss out—book your tickets now!
Get your tickets!Choose the mode that fits your workflow—Local for simplicity, Interactive for precision, YOLO for speed.
Encourage exploration of all modes to find the right balance for your team.
Note
Please find the Cursor Local,Interactive, Yolo mode PRs for reference.
This is a free third party commenting service we are using for you, which needs you to sign in to post a comment, but the good bit is you can stay anonymous while commenting.