29 lines
919 B
Swift
29 lines
919 B
Swift
import Foundation
|
||
import SwiftData
|
||
|
||
/// 打卡习惯的持久化实体(对应 Android Room 的 @Entity)。
|
||
@Model
|
||
public final class HabitEntity {
|
||
public var id: String
|
||
public var title: String
|
||
public var detail: String
|
||
public var streakDays: Int
|
||
public var createdAt: Date
|
||
|
||
public init(id: String, title: String, detail: String, streakDays: Int, createdAt: Date) {
|
||
self.id = id
|
||
self.title = title
|
||
self.detail = detail
|
||
self.streakDays = streakDays
|
||
self.createdAt = createdAt
|
||
}
|
||
}
|
||
|
||
/// SwiftData 容器工厂(对应 Android RoomDatabase)。
|
||
public enum PersistenceController {
|
||
public static func makeModelContainer(inMemory: Bool = false) throws -> ModelContainer {
|
||
let configuration = ModelConfiguration(isStoredInMemoryOnly: inMemory)
|
||
return try ModelContainer(for: HabitEntity.self, configurations: configuration)
|
||
}
|
||
}
|