Naming Collision Between Model Attribute and Enum Case in SwiftData and CloudKit

There is a conflict in SwiftData (specifically when synced with CloudKit) when a @Model attribute shares the same name as a case within its assigned enum type. When this occurs, accessing the attribute on a model instance consistently returns the value corresponding to the enum case name, rather than the actual value persisted in the database.

Steps to Reproduce

  1. Define an enumeration (e.g., Status) with a case that matches a planned property name (e.g., case status).

  2. Create a SwiftData @Model that uses this enum.

  3. Name the property in the model the same as the enum case.

  4. Attempt to save and then retrieve the value.

Example Code

enum TaskStatus: String, Codable {
    case status // The conflict source
    case pending
    case completed
}

@Model
class TodoItem {
    // Conflict: Property name matches enum case name
    var status: TaskStatus 
    
    init(status: TaskStatus) {
        self.status = status
    }
}

Expected Behavior

The property item.status should return the value stored in the database (e.g., .pending or .completed).

Actual Behavior

The property item.status consistently resolves to the enum case .status, ignoring the actual persisted data.

Thanks for reporting the issue. I indeed see that the value changes to the case name after synchronization :-(.

Do you have a feedback report yet? If not, would you mind to file one and share your report ID here? Thanks.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Naming Collision Between Model Attribute and Enum Case in SwiftData and CloudKit
 
 
Q