I am migrating our app to Swift 6, and I am encountering the following error while trying to migrate part of the code base.
Xcode 16 with swift 6 asked me to add the @preconcurrency attribute before the protocol name (see image in point 1). However, when I switch to Xcode 15.4 with swift 5, it asks me to place the @preconcurrency attribute at the beginning of the extension (see image in point 2). If I do this, it then asks me to remove it (see image in point 3).
Is there any way to make this Swift 6 migration change work in both Swift 5.1 and 6.0?
Does anyone know how to fix this?
1 – This is the error I got when I used it with Xcode 16 and Swift 6:
2 – This is the error I got after applying the Xcode suggestion from point 1, using Xcode 15.4 and Swift 5.1:
3 – This is the error I got after applying the Xcode suggestion from point 2, using Xcode 15.4 and Swift 5.1.
This is the simplified version of the code base:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
}
.padding()
}
}
extension ContentView: NamedView {
var analyticsName: String { "test" }
}
protocol NamedView {
var analyticsName: String { get }
}
3