Loading...
Loading...
Compare original and translation side by side
.claude/mcps/swiftlens.json{
"mcpServers": {
"swiftlens": {
"description": "SwiftLens MCP provides semantic Swift analysis via SourceKit-LSP",
"command": "uvx",
"args": ["swiftlens"]
}
}
}references/swiftlens-mcp-claude-code.md.claude/mcps/swiftlens.json{
"mcpServers": {
"swiftlens": {
"description": "SwiftLens MCP provides semantic Swift analysis via SourceKit-LSP",
"command": "uvx",
"args": ["swiftlens"]
}
}
}references/swiftlens-mcp-claude-code.mdvar greeting = "Hello"var string = "Hello"var greeting = "Hello"var string = "Hello"@MainActorSendable@MainActorSendable// Parallel execution with async let
func fetchData() async -> (String, Int) {
async let stringData = fetchString()
async let intData = fetchInt()
return await (stringData, intData)
}
// Always check cancellation in long-running operations
func process(_ items: [Item]) async throws -> [Result] {
var results: [Result] = []
for item in items {
try Task.checkCancellation()
results.append(await process(item))
}
return results
}// Parallel execution with async let
func fetchData() async -> (String, Int) {
async let stringData = fetchString()
async let intData = fetchInt()
return await (stringData, intData)
}
// Always check cancellation in long-running operations
func process(_ items: [Item]) async throws -> [Result] {
var results: [Result] = []
for item in items {
try Task.checkCancellation()
results.append(await process(item))
}
return results
}// Apply at type level for consistent isolation
@MainActor
class ContentViewModel: ObservableObject {
@Published var images: [UIImage] = []
func fetchData() async throws {
self.images = try await fetchImages()
}
}
// Avoid MainActor.run when direct await works
await doMainActorStuff() // Good
await MainActor.run { doMainActorStuff() } // Unnecessary// Apply at type level for consistent isolation
@MainActor
class ContentViewModel: ObservableObject {
@Published var images: [UIImage] = []
func fetchData() async throws {
self.images = try await fetchImages()
}
}
// Avoid MainActor.run when direct await works
await doMainActorStuff() // Good
await MainActor.run { doMainActorStuff() } // Unnecessaryactor DataCache {
private var cache: [String: Data] = [:]
func store(_ data: Data, forKey key: String) {
cache[key] = data // No await needed inside actor
}
nonisolated func cacheType() -> String {
return "DataCache" // No await needed - doesn't access isolated state
}
}actor DataCache {
private var cache: [String: Data] = [:]
func store(_ data: Data, forKey key: String) {
cache[key] = data // No await needed inside actor
}
nonisolated func cacheType() -> String {
return "DataCache" // No await needed - doesn't access isolated state
}
}asyncDispatchSemaphoreTask.checkCancellation()asyncDispatchSemaphoreTask.checkCancellation()UpperCamelCaselowerCamelCase-able-ible-ingEquatableProgressReportingmakex.makeIterator()x.sort()x.sorted()UpperCamelCaselowerCamelCase-able-ible-ingEquatableProgressReportingmakex.makeIterator()x.sort()x.sorted()x.distance(to: y)x.append(y)x.sort()x.distance(to: y)x.append(y)x.sort()min(number1, number2)Int64(someUInt32)x.removeBoxes(havingLength: 12)min(number1, number2)Int64(someUInt32)x.removeBoxes(havingLength: 12)@MainActor
struct LogInView: View {
@StateObject private var model = ViewModel()
}@MainActor
struct LogInView: View {
@StateObject private var model = ViewModel()
}static let config = Config() // Constant - OK
@MainActor static var state = State() // Actor-isolated - OK
nonisolated(unsafe) var cache = [String: Data]() // Unsafe - use with cautionstatic let config = Config() // 常量 - 合法
@MainActor static var state = State() // Actor隔离 - 合法
nonisolated(unsafe) var cache = [String: Data]() // 不安全 - 谨慎使用@UIApplicationMain@NSApplicationMain@mainany@UIApplicationMain@NSApplicationMain@mainany// Basic availability
@available(macOS 15, iOS 18, *)
func modernAPI() { }
// Deprecation with message
@available(*, deprecated, message: "Use newMethod() instead")
func oldMethod() { }
// Renaming with auto-fix
@available(*, unavailable, renamed: "newMethod")
func oldMethod() { }
// Runtime checking
if #available(iOS 18, *) {
// iOS 18+ code
}
// Inverted checking (Swift 5.6+)
if #unavailable(iOS 18, *) {
// iOS 17 and lower
}deprecatedobsoletedunavailable// Basic availability
@available(macOS 15, iOS 18, *)
func modernAPI() { }
// Deprecation with message
@available(*, deprecated, message: "Use newMethod() instead")
func oldMethod() { }
// Renaming with auto-fix
@available(*, unavailable, renamed: "newMethod")
func oldMethod() { }
// Runtime checking
if #available(iOS 18, *) {
// iOS 18+ code
}
// Inverted checking (Swift 5.6+)
if #unavailable(iOS 18, *) {
// iOS 17 and lower
}deprecatedobsoletedunavailable@MainActor@MainActorcount(where:)filter().countInlineArraySendablecount(where:)filter().countInlineArraySendable@available@available#available@available#available@available