Done with CoreData working. Saving, updating and deleting are working correct now
This commit is contained in:
parent
b4704bd4fc
commit
3eb5fb73eb
@ -8,8 +8,11 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct CreatedClassView: View {
|
struct CreatedClassView: View {
|
||||||
let _class: ClassModel
|
@ObservedObject var _class: ClassModel
|
||||||
|
var provider = ClassProvider.shared
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
let existingCopy = try? provider.viewContext.existingObject(with: _class.objectID)
|
||||||
|
if let check = existingCopy {
|
||||||
HStack(spacing: 10) {
|
HStack(spacing: 10) {
|
||||||
VStack {
|
VStack {
|
||||||
Text(getTimeString(_class.starttime))
|
Text(getTimeString(_class.starttime))
|
||||||
@ -37,6 +40,7 @@ struct CreatedClassView: View {
|
|||||||
.cornerRadius(20)
|
.cornerRadius(20)
|
||||||
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
@ -62,7 +62,6 @@ struct ScheduleView: View {
|
|||||||
CreatedClassView(_class: _class)
|
CreatedClassView(_class: _class)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
selectedClass = _class
|
selectedClass = _class
|
||||||
print(selectedClass)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,10 +141,10 @@ struct CreateEditClassView: View {
|
|||||||
Button {
|
Button {
|
||||||
do {
|
do {
|
||||||
try delete(vm._class)
|
try delete(vm._class)
|
||||||
|
dismiss()
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
dismiss()
|
|
||||||
} label: {
|
} label: {
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
@ -194,7 +194,6 @@ struct CreateEditClassView: View {
|
|||||||
try context.save()
|
try context.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,10 @@ final class ClassProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newContext: NSManagedObjectContext {
|
var newContext: NSManagedObjectContext {
|
||||||
persistentContainer.newBackgroundContext()
|
//persistentContainer.newBackgroundContext()
|
||||||
|
let context = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
|
||||||
|
context.persistentStoreCoordinator = persistentContainer.persistentStoreCoordinator
|
||||||
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user