Automates migration of Swift codebases to Swift Concurrency. Benefits iOS, macOS, tvOS, watchOS, and visionOS developers by identifying and refactoring legacy code. Integrates with Xcode and CI/CD pipelines to streamline the migration process.
git clone https://github.com/kylehughes/the-unofficial-swift-concurrency-migration-skill.gitAutomates migration of Swift codebases to Swift Concurrency. Benefits iOS, macOS, tvOS, watchOS, and visionOS developers by identifying and refactoring legacy code. Integrates with Xcode and CI/CD pipelines to streamline the migration process.
1. **Prepare Your Codebase**: Ensure your project is using Swift 5.5+ and has a backup (e.g., via Git). Open the project in Xcode and enable Swift Concurrency warnings in Build Settings (`SWIFT_ENABLE_LIBRARY_EVOLUTION` and `SWIFT_CONCURRENCY_STRICT` if needed). 2. **Run the Migration**: Use the prompt template above and provide either a code snippet or file path. Specify areas to focus on (e.g., networking, file I/O) if needed. For large projects, break the migration into modules to avoid overwhelming the AI. 3. **Review the Diff**: The AI will provide a diff of changes. Manually verify critical sections, especially those involving thread safety (e.g., `Actor` isolation, `Sendable` conformance). 4. **Test Thoroughly**: Update unit tests to use `async` test methods (e.g., `XCTestCase.async` in Xcode 15+). Run tests in a staging environment to catch race conditions or deadlocks. 5. **Integrate with CI/CD**: Add the migration steps to your CI pipeline (e.g., GitHub Actions, Bitrise). Use tools like `swift-format` to auto-format changes and `swiftlint` to enforce style guidelines. **Tips for Better Results:** - Use `// swift-format-ignore` comments to skip formatting for complex migrations. - For mixed Objective-C/Swift projects, focus on Swift files first and handle Objective-C separately (e.g., using `NSOperation` wrappers). - Leverage Xcode’s "Convert to Current Swift Syntax" tool for initial cleanup before using this skill.
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/kylehughes/the-unofficial-swift-concurrency-migration-skillCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Migrate the following Swift codebase to Swift Concurrency: [CODE_SNIPPET_OR_FILE_PATH]. Identify all blocking calls, GCD patterns, and completion handlers. Replace them with async/await, actors, and structured concurrency. Ensure thread safety and maintain backward compatibility where needed. Provide a diff of changes and highlight potential pitfalls. Focus on [SPECIFIC_AREAS] if mentioned.
Here’s a migration of a legacy Swift codebase for a `NetworkManager` class that previously used GCD for asynchronous operations. The original code relied on `DispatchQueue` and completion handlers, which have been refactored to use Swift Concurrency’s `async/await` and `Task` APIs.
**Original Code (GCD-based):**
```swift
class NetworkManager {
func fetchUserData(userId: String, completion: @escaping (Result<User, Error>) -> Void) {
DispatchQueue.global(qos: .userInitiated).async {
let url = URL(string: "https://api.example.com/users/\\(userId)")!
URLSession.shared.dataTask(with: url) { data, _, error in
if let error = error {
completion(.failure(error))
return
}
guard let data = data else {
completion(.failure(NetworkError.invalidData))
return
}
do {
let user = try JSONDecoder().decode(User.self, from: data)
DispatchQueue.main.async {
completion(.success(user))
}
} catch {
completion(.failure(error))
}
}.resume()
}
}
}
```
**Migrated Code (Swift Concurrency):**
```swift
class NetworkManager {
func fetchUserData(userId: String) async throws -> User {
let url = URL(string: "https://api.example.com/users/\\(userId)")!
let (data, _) = try await URLSession.shared.data(from: url)
return try JSONDecoder().decode(User.self, from: data)
}
}
```
**Key Changes:**
1. Replaced `DispatchQueue.global` with Swift Concurrency’s implicit background execution via `async`.
2. Converted the completion handler pattern to `async/await`, eliminating the need for manual `DispatchQueue.main` calls.
3. Simplified error handling by leveraging Swift’s native `throws` mechanism.
4. Removed the need for explicit `resume()` calls, as `URLSession.data(from:)` is already an async function.
**Potential Pitfalls:**
- If the codebase relies on `DispatchQueue.main` for UI updates, ensure the caller uses `MainActor` or dispatches UI updates explicitly.
- Thread safety must be reviewed for shared mutable state, especially in classes marked as `final` or `nonisolated`.
- Legacy code using `NSOperationQueue` or `Operation` may require additional refactoring to align with Swift Concurrency’s structured tasks.
**Next Steps:**
1. Replace all instances of `DispatchQueue` with `Task` or `async/await` where appropriate.
2. Audit `Actor`-isolated properties to ensure no data races.
3. Update unit tests to use `async` test methods (e.g., `XCTestCase.async` in Xcode 15+).
4. Run the migrated code in a staging environment to verify performance and correctness.Swift 6 concurrency patterns for AI agents
IronCalc is a spreadsheet engine and ecosystem
ITIL-aligned IT service management platform
Customer feedback management made simple
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan