diff --git a/AboTracker/PersistenceController.swift b/AboTracker/PersistenceController.swift
new file mode 100644
index 0000000..206ef32
--- /dev/null
+++ b/AboTracker/PersistenceController.swift
@@ -0,0 +1,20 @@
+import CoreData
+
+struct PersistenceController {
+ static let shared = PersistenceController()
+
+ let container: NSPersistentContainer
+
+ init() {
+ container = NSPersistentContainer(name: "SubscriptionModel")
+ container.loadPersistentStores { (storeDescription, error) in
+ if let error = error as NSError? {
+ fatalError("Unresolved error \(error), \(error.userInfo)")
+ }
+ }
+ }
+
+ var context: NSManagedObjectContext {
+ return container.viewContext
+ }
+}
diff --git a/AboTracker/SubscriptionModel.xcdatamodeld/SubscriptionModel.xcdatamodel/contents b/AboTracker/SubscriptionModel.xcdatamodeld/SubscriptionModel.xcdatamodel/contents
new file mode 100644
index 0000000..b0a154d
--- /dev/null
+++ b/AboTracker/SubscriptionModel.xcdatamodeld/SubscriptionModel.xcdatamodel/contents
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AboTracker/data/Payment+CoreDataClass.swift b/AboTracker/data/Payment+CoreDataClass.swift
new file mode 100644
index 0000000..7b4beec
--- /dev/null
+++ b/AboTracker/data/Payment+CoreDataClass.swift
@@ -0,0 +1,10 @@
+import Foundation
+import CoreData
+
+@objc(Payment)
+public class Payment: NSManagedObject {
+ @NSManaged public var amount: Double
+ @NSManaged public var interval: String
+ @NSManaged public var startDate: Date
+ @NSManaged public var subscription: Subscription
+}
diff --git a/AboTracker/data/Payment+CoreDataProperties.swift b/AboTracker/data/Payment+CoreDataProperties.swift
new file mode 100644
index 0000000..fdcf70b
--- /dev/null
+++ b/AboTracker/data/Payment+CoreDataProperties.swift
@@ -0,0 +1,28 @@
+//
+// Payment+CoreDataProperties.swift
+// AboTracker
+//
+// Created by Keyvan Atashfaraz on 02.07.24.
+//
+//
+
+import Foundation
+import CoreData
+
+
+extension Payment {
+
+ @nonobjc public class func fetchRequest() -> NSFetchRequest {
+ return NSFetchRequest(entityName: "Payment")
+ }
+
+ @NSManaged public var amount: Double
+ @NSManaged public var interval: String?
+ @NSManaged public var startDate: Date?
+ @NSManaged public var subscription: Subscription?
+
+}
+
+extension Payment : Identifiable {
+
+}
diff --git a/AboTracker/data/Subscription+CoreDataClass.swift b/AboTracker/data/Subscription+CoreDataClass.swift
new file mode 100644
index 0000000..303c941
--- /dev/null
+++ b/AboTracker/data/Subscription+CoreDataClass.swift
@@ -0,0 +1,10 @@
+import Foundation
+import CoreData
+import SwiftUI
+
+@objc(Subscription)
+public class Subscription: NSManagedObject {
+ @NSManaged public var name: String
+ @NSManaged public var color: UIColor
+ @NSManaged public var payments: Set
+}
diff --git a/AboTracker/data/Subscription+CoreDataProperties.swift b/AboTracker/data/Subscription+CoreDataProperties.swift
new file mode 100644
index 0000000..a212918
--- /dev/null
+++ b/AboTracker/data/Subscription+CoreDataProperties.swift
@@ -0,0 +1,27 @@
+//
+// Subscription+CoreDataProperties.swift
+// AboTracker
+//
+// Created by Keyvan Atashfaraz on 02.07.24.
+//
+//
+
+import Foundation
+import CoreData
+
+
+extension Subscription {
+
+ @nonobjc public class func fetchRequest() -> NSFetchRequest {
+ return NSFetchRequest(entityName: "Subscription")
+ }
+
+ @NSManaged public var name: String?
+ @NSManaged public var color: NSObject?
+ @NSManaged public var payments: Payment?
+
+}
+
+extension Subscription : Identifiable {
+
+}
diff --git a/AboTracker/views/PaymentCalendarView.swift b/AboTracker/views/PaymentCalendarView.swift
index 6799db4..fb760cb 100644
--- a/AboTracker/views/PaymentCalendarView.swift
+++ b/AboTracker/views/PaymentCalendarView.swift
@@ -6,6 +6,7 @@ struct PaymentCalendarView: View {
let dateFormatter = DateFormatter()
@State private var currentDate = Date()
+ private let initialDate = Date()
var body: some View {
VStack {
@@ -13,11 +14,43 @@ struct PaymentCalendarView: View {
.font(.title)
.padding()
- Text(currentMonthYear())
- .font(.headline)
- .padding()
+ HStack {
+ Button(action: {
+ self.currentDate = self.calendar.date(byAdding: .month, value: -1, to: self.currentDate)!
+ }) {
+ Image(systemName: "chevron.left.circle.fill")
+ .font(.title)
+ }
+
+ Button(action: {
+ self.currentDate = self.initialDate
+ }) {
+ Text("Current Month")
+ .font(.headline)
+ }
+
+ Button(action: {
+ self.currentDate = self.calendar.date(byAdding: .month, value: 1, to: self.currentDate)!
+ }) {
+ Image(systemName: "chevron.right.circle.fill")
+ .font(.title)
+ }
+ }
+ .padding(.horizontal)
calendarView()
+ .gesture(
+ DragGesture()
+ .onEnded { gesture in
+ if gesture.translation.width < 0 {
+ // Swipe left -> move to next month
+ self.currentDate = self.calendar.date(byAdding: .month, value: 1, to: self.currentDate)!
+ } else {
+ // Swipe right -> move to previous month
+ self.currentDate = self.calendar.date(byAdding: .month, value: -1, to: self.currentDate)!
+ }
+ }
+ )
}
.padding()
}
@@ -77,7 +110,6 @@ struct PaymentCalendarView: View {
return date >= startOfWeek && date <= endOfWeek && calendar.component(.weekday, from: payment.startDate) == calendar.component(.weekday, from: date)
case .monthly:
- // ToDo: Payment not visible if Payment is at example at 31th of month, but month only has 30 days
return calendar.component(.day, from: payment.startDate) == calendar.component(.day, from: date)
case .quarter: