Xcode 16 Beta 3: "Cannot expand accessors on variable declared with 'let'"

Running into this new issue in beta 3.

All of our immutable model attributes are now triggering swift compiler error from the title (tied to swift 6 - warning in swift 5).

Neither warning or error show up on previous builds.

Anyone else running into this? Hopefully not a limitation on swiftData that attributes must be mutable?

filed as: FB14379932 (new in Xcode 16 beta3: "cannot expand accessors on variable declared with 'let'" in SwiftData Models)

Answered by DTS Engineer in 796071022

Yeah, this is a change introduced in beta 3. Every SwiftData attribute is converted (expanded) to a computed property with accessors via SwiftMacro, and since beta 3, the conversion requires the attribute be var.

I think you can go ahead to apply the change to your SwiftData attributes. Doing that shouldn't have any negative impact.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Yeah, this is a change introduced in beta 3. Every SwiftData attribute is converted (expanded) to a computed property with accessors via SwiftMacro, and since beta 3, the conversion requires the attribute be var.

I think you can go ahead to apply the change to your SwiftData attributes. Doing that shouldn't have any negative impact.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank you for confirming the change. Is this going to be a documented limitation of SwiftData?

It is useful to be able to express the immutability of particular model attributes. I can understand if SwiftData may now be unable to handle that immutability constraint, but that change seems like it should be a documented property of SwiftData and not just a compiler error.

If it isn't a SwiftData design decision but a limitation of macros I would encourage the restoration of the previously shipping behavior.

Disallowing let for an attribute that is converted to a computed property is a Swift language feature, and so the change is intentional.

I agree though that there is a need to express immutability for a SwiftData model attribute, and so will encourage you to voice your opinion in your feedback report for the team to consider.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Xcode 16 Beta 3: "Cannot expand accessors on variable declared with 'let'"
 
 
Q