I am starting to learn SwiftData and have a simple model and Enum.
import Foundation
import SwiftData
@Model
final class Member {
var id : Int64
var platform : Platform
var bungieId : BungieId
var displayName : String
var sync:Bool = false
init(fromUserInfoCard card:IsUserInfoCard) {
id = Int64(card.membershipId)!
bungieId = BungieId(fromUserInfoCard: card)
platform = Platform(value: card.membershipType)
displayName = card.displayName ?? ""
sync = false
}
var isValid : Bool {
get {
return platform != Platform.unknown && bungieId.isValid
}
}
}
import SwiftData
enum Platform : Int32, Codable {
case unknown = 0
case xbox = 1
case playstation = 2
case steam = 3
case blizzard = 4
case stadia = 5
case epic = 6
case tigerDemon = 10
case bungieNext = 254
init(value:Int32 = 0) {
let tmp = Platform(rawValue:value)
if let out = tmp {
self = out
return
}
self = Platform.unknown
}
}
When I try to run this i get this error:
No exact matches in call to instance method setValue
Which is at the platform property of Member. If I change Platform init to have a default value like so:
init(value:Int32 = 0) {
let tmp = Platform(rawValue:value)
if let out = tmp {
self = out
return
}
self = Platform.unknown
}
Then the error goes away. I cant find any documentation on this, but just assume I need to provide a default value. Does anyone know what is going on?