Files
ios-client/IosClientKit/Sources/CoreDatabase/PersistenceController.swift
2026-09-14 21:10:44 +08:00

29 lines
919 B
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}
}