While trying to use Xcode 27, I received compiler errors related to the unsafe keyword being unnecessary. Removing the keyword addressed the error, but when the same package was then built in Xcode 26, an error was generated saying that the keyword unsafe was missing. This makes it difficult to interchangeably use Xcode 26 and 27, while preparing for macOS 27.
Package.swift:
// swift-tools-version: 6.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let swiftSettings: [SwiftSetting] = [
.swiftLanguageMode(.v6),
.defaultIsolation(nil),
.strictMemorySafety(),
.treatAllWarnings(as: .error),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableUpcomingFeature("InferIsolatedConformances"),
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
.enableUpcomingFeature("ImmutableWeakCaptures")
]
let package = Package(
name: "Unsafety",
products: [.library(name: "Unsafety", targets: ["Unsafety"])],
targets: [.target(name: "Unsafety", swiftSettings: swiftSettings)]
)
Under Xcode 27.0 beta 2 (27A5209h)
public func hello() {
let str = "Hello World"
unsafe str.withCString { ptr in /* some code */ }
}
Error:
Unsafety.swift:3:3: No unsafe operations occur within 'unsafe' expression
Under Xcode 26.6 (17F113)
public func hello() {
let str = "Hello World"
str.withCString { ptr in /* some code */ }
}
Error:
Expression uses unsafe constructs but is not marked with 'unsafe'
Is this an expected change and is there a workaround that let's us continue to build in both toolchains?