58 lines
1.6 KiB
Swift
58 lines
1.6 KiB
Swift
|
||
import SwiftUI
|
||
import UIKit
|
||
import SwiftData
|
||
|
||
@main
|
||
struct WakeApp: App {
|
||
// init() {
|
||
// // 打印所有可用的字体
|
||
// print("\n=== 所有可用的字体 ===")
|
||
// for family in UIFont.familyNames.sorted() {
|
||
// print("\n\(family):")
|
||
// for name in UIFont.fontNames(forFamilyName: family).sorted() {
|
||
// print(" - \(name)")
|
||
// }
|
||
// }
|
||
// }
|
||
// 使用更简单的方式创建模型容器
|
||
let container: ModelContainer
|
||
|
||
init() {
|
||
do {
|
||
// 1. 先尝试正常加载
|
||
container = try ModelContainer(for: Login.self)
|
||
} catch {
|
||
// 2. 如果失败,尝试删除旧的存储文件
|
||
let url = URL.applicationSupportDirectory.appending(path: "default.store")
|
||
if FileManager.default.fileExists(atPath: url.path) {
|
||
try? FileManager.default.removeItem(at: url)
|
||
}
|
||
|
||
// 3. 重新创建容器
|
||
container = try! ModelContainer(for: Login.self)
|
||
}
|
||
}
|
||
|
||
|
||
var body: some Scene {
|
||
WindowGroup {
|
||
ContentView()
|
||
// SettingsView()
|
||
// 导航栏按钮
|
||
// TabView{
|
||
// ContentView()
|
||
// .tabItem{
|
||
// Label("wake", systemImage: "book")
|
||
// }
|
||
// SettingView()
|
||
// .tabItem{
|
||
// Label("setting", systemImage: "gear")
|
||
// }
|
||
// }
|
||
}
|
||
// 注入模型容器到环境中
|
||
.modelContainer(container)
|
||
}
|
||
}
|