SwiftData enum No exact matches in call to instance method 'setValue' error

I'm getting an "No exact matches in call to instance method 'setValue'" error for a property that has a enum as a value. How do I fix this? Any help would be appreciated.

enum FluidUnit: CaseIterable, Identifiable {
  case ounce, liter
  var id: Self { self }

  var title: String {
    switch self {
    case .ounce:
      return "ounce"
    case .liter:
      return "liters"
    }
  }
}

@Model
class Drink: Identifiable, Hashable {

  let id: UUID = UUID()
  let name: String = ""
  var shortName: String = ""
  var amount: Double = 0.0
  let unitOfMeasure: FluidUnit = FluidUnit.ounce
  let date: Date = Date()
  var image: String = "water"
  var favorite: Bool = false

  init(name: String, amount: Double, unitOfMeasure: FluidUnit, image: String, favorite: Bool = false, shortName: String = "") {
    self.id = UUID()
    self.name = name
    self.amount = amount
    self.unitOfMeasure = unitOfMeasure
    self.date = Date()
    self.image = image
    self.favorite = favorite
    self.shortName = shortName
  }

  static func == (lhs: Drink, rhs: Drink) -> Bool {
    lhs.id == rhs.id
  }

  func hash(into hasher: inout Hasher) {
      hasher.combine(id)
  }
}

Accepted Reply

I figured it out. I added Codable to the enum and cleaned the build folder and the error went away.

Replies

I figured it out. I added Codable to the enum and cleaned the build folder and the error went away.