Global static property concurrency-safe error

Hi there! I'm new to Swift and I'm currently learning by reading the documentation. I'm now reading the Type Property Syntax part of the Properties chapter, but I encountered some issues.
I'm trying to run the code snippet provided in the documentation:

struct SomeStructure {
    static var storedTypeProperty = "Some value."
    static var computedTypeProperty: Int {
        return 1
    }
}

But I got an error from Xcode Static property 'storedTypeProperty' is not concurrency-safe because it is nonisolated global shared mutable state
I asked Google Gemini and Claude about it and they said that it's the documentation out of date because in Swift 6, there's an enforced-by-default strict concurrency protection so that it's not allowed to have such global type property. I switched the build language for my Playground from Swift 6 to Swift 5 and the error is gone and the code can be built.
But I'm still curious that is it actually the documentation outdated? Because it's been almost two years since the release of Swift 6 and no one is updating the docs? I also searched in the swift-book GitHub repo and I found nothing about this content. I don't believe this can be left undiscussed for so long.
So is it actually the documentation outdated, or am I doing anything wrong? I'm really confused because I'm new to Swift, and I can't believed that it can be the problem of the documentation that is remained unfixed for so long. Can anyone help explain this to me! I would deeply appreciate it!

1 Like

Yes, the compiler is correct. Yes, the documentation needs to be updated for Swift 6 mode. Yes, it's turned off in Swift 5 mode because the compiler won't check for global mutation.

I suggest keeping your playground in Swift 6 mode and simply comment out code that won't compile. Then, when you get to the Swift concurrency section of the book, look at the code you have commented and see which rules caused them not to compile.

1 Like

The error is correct, and you're right in your assumption that the concurrency documentation is lagging behind, while the non-concurrency documentation hasn’t been updated for Swift concurrency at all. For example, the documentation never lists actor as an available Swift type. That said, there is documentation explaining Swift’s isolation model, although it’s very well hidden: Unsafe Global and Static Variables

1 Like

Thank you for explaining this in detail! I will keep learning!

Thank you for your reply! This helps me understand now!