krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

DayByDay/Profiles/Profile.swift

33 lines · 914 bytes

1 symbol in this file
 1//
 2//  Profile.swift
 3//  DayByDay
 4//
 5
 6import Foundation
 7import SwiftData
 8
 9@Model
10final class Profile {
11    var id: UUID
12    var name: String
13    var avatarRaw: String
14    var colorRaw: Int
15    var birthdayMonth: Int?
16    var birthdayDay: Int?
17    var createdAt: Date
18    @Relationship(deleteRule: .cascade, inverse: \AnswerRecord.profile)
19    var answers: [AnswerRecord] = []
20
21    init(name: String, avatar: AvatarAnimal, color: ProfileColor, birthdayMonth: Int?, birthdayDay: Int?, createdAt: Date = .now) {
22        self.id = UUID()
23        self.name = name
24        self.avatarRaw = avatar.rawValue
25        self.colorRaw = color.rawValue
26        self.birthdayMonth = birthdayMonth
27        self.birthdayDay = birthdayDay
28        self.createdAt = createdAt
29    }
30
31    var avatar: AvatarAnimal { AvatarAnimal(rawValue: avatarRaw) ?? .cat }
32    var color: ProfileColor { ProfileColor(rawValue: colorRaw) ?? .blue }
33}