visionOS and SwiftData: 'member' macro cannot be attached to property

  1. Create a new Multiplatform App project
  2. Select SwiftData as a storage option
  3. In the main Target add Apple Vision as a Supported Destination target
  4. Select "Apple Vision Pro" as a run destination
  5. Build and run (start the active scheme)

Expect: Successful build

Actual: Build error:

/var/folders/25/7fgb4nf92lx09_gptkqy42f80000gn/T/swift-generated-sources/@__swiftmacro_6Sherpa4Item5ModelfMm_.swift:2:13 'member' macro cannot be attached to property

The code (with the macro expanded) looks like this:

@Model
final class Item {
    var timestamp: Date
    
    init(timestamp: Date) {
        self.timestamp = timestamp
    }
@Transient
private var _$backingData: any SwiftData.BackingData<Item> = SwiftData.DefaultBackingData(for: Item.self) // 'member' macro cannot be attached to property

public var backingData: any SwiftData.BackingData<Item> {
    get {
        _$backingData
    }
    set {
        _$backingData = newValue
    }
}

static func schemaMetadata() -> [(String, AnyKeyPath, Any?, Any?)] {
  return [
    ("timestamp", \Item.timestamp, nil, nil)
  ]
}

init(backingData: any SwiftData.BackingData<Item>) {
  self.backingData = backingData
}

@Transient
private let _$observationRegistrar = Observation.ObservationRegistrar() // 'member' macro cannot be attached to property
}
Answered by davidweiss in 761606022

Found this in the release notes for beta 6 under known issues: https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes

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

and

visionOS projects that use the @Observable property wrapper will fail to build in Xcode 15 beta 3. (111494849)

Seems related...

This is with Xcode Version 15.0 beta 6 (15A5219j)

Has SwiftData been implemented on visionOS yet? I hasn't been. I don't know about beta 6.

Accepted Answer

Found this in the release notes for beta 6 under known issues: https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes

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

and

visionOS projects that use the @Observable property wrapper will fail to build in Xcode 15 beta 3. (111494849)

Seems related...

visionOS and SwiftData: 'member' macro cannot be attached to property
 
 
Q