SwiftData CloudKit integration requires that all attributes be optional, or have a default value set

After install XCode 15 beta 6:

@Model
class WordResult {
    var text = ""
    var translation:[String] = []

      init(){

      }
}

got this error:

Variable 'self._$backingData' used before being initialized

so I changed to :

@Model
class WordResult {
    var text:String
    var translation:[String]

    
    init(){
        self.text = ""
        self.translation = []
    }
}

Then got this:

CloudKit integration requires that all attributes be optional, or have a default value set

It seems it can not work with cloudkit now.

  • It's fixed in Xcode 15.0 beta 7!!

Add a Comment

Accepted Reply

According to the Xcode 15 Beta 7 Release Notes:

SwiftData

Resolved Issues

  • Fixed: @Model classes with initial values for stored properties result in an error that self._$backingData is used before being initialized. (113572344)

New builds with the new Xcode beta should not run into those issues.

Replies

The same issue as this post: https://developer.apple.com/forums/thread/735342

But yes a few people have the same issue, myself included...

Thanx, very helpful

Same for me. It seems everything needs to be optional now, and not have a default value, which makes for uglier code. But

var text:String?
var translation:[String]?

Should work fine for you

  • This workaround is not perfect. Still need Apple Fix this. check optional is annoying.

Add a Comment

According to the Xcode 15 Beta 7 Release Notes:

SwiftData

Resolved Issues

  • Fixed: @Model classes with initial values for stored properties result in an error that self._$backingData is used before being initialized. (113572344)

New builds with the new Xcode beta should not run into those issues.