-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackBudgetApp.swift
More file actions
74 lines (68 loc) · 2.53 KB
/
Copy pathStackBudgetApp.swift
File metadata and controls
74 lines (68 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import SwiftUI
@main
struct StackBudgetApp: App {
@StateObject private var budgetManager = BudgetManager()
@StateObject private var recurringItemsManager = RecurringItemsManager()
init() {
// Force Light Mode
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
windowScene.windows.first?.overrideUserInterfaceStyle = .light
}
}
private func createSampleBudget() {
let startingBalance = Double.random(in: 1000...5000).rounded()
let sampleItems = [
BudgetItem(
title: "Current Balance",
amount: startingBalance,
date: Date(),
isCurrentBalance: true
),
BudgetItem(
title: "Paycheck",
amount: 2000,
date: Calendar.current.date(byAdding: .day, value: 1, to: Date()) ?? Date(),
isInflux: true
),
BudgetItem(
title: "Rent",
amount: 1200,
date: Calendar.current.date(byAdding: .day, value: 2, to: Date()) ?? Date(),
isInflux: false
),
BudgetItem(
title: "Cellphone Bill",
amount: 85,
date: Calendar.current.date(byAdding: .day, value: 3, to: Date()) ?? Date(),
isInflux: false
),
BudgetItem(
title: "Grocery Shopping",
amount: 150,
date: Calendar.current.date(byAdding: .day, value: 4, to: Date()) ?? Date(),
isInflux: false
)
]
let sampleBudget = StackBudget(
title: "Sample Budget",
items: sampleItems,
createdAt: Date(),
colorName: Color.customPalette.randomElement()?.name ?? "Ocean"
)
budgetManager.addBudget(sampleBudget)
}
var body: some Scene {
WindowGroup {
BudgetListView()
.environmentObject(budgetManager)
.environmentObject(recurringItemsManager)
.task {
if budgetManager.budgets.isEmpty && !UserDefaults.standard.bool(forKey: "didCreateInitialBudget") {
createSampleBudget()
UserDefaults.standard.set(true, forKey: "didCreateInitialBudget")
}
}
.preferredColorScheme(.light) // Force light mode at the SwiftUI level
}
}
}