Any suggestion that could point me in the right direction? This keeps crashing and doesn't seem to write data to the Coredata entity. Thank you
import SwiftUI
import CoreData
struct DataView: View {
@State var myDetail = String("")
@ObservedObject private var locationManager = LocationManager()
@Environment(\.managedObjectContext) var moc
@FetchRequest(entity: UserLocation.entity(), sortDescriptors:[NSSortDescriptor(key: "id", ascending: true)]) var userLocations: FetchedResults<UserLocation>
var body: some View {
NavigationView {
VStack {
VStack {
TextField("Short Description where you are", text: $myDetail)
.textFieldStyle(RoundedBorderTextFieldStyle())
.foregroundColor(Color.blue)
.background(Color.blue)
.padding(10)
.border(Color.green, width: 5)
Button("Add Location") {
let myDate = self.getTodaysDate()
let myTime = self.getTodaysTime()
let myLatitude = self.getLatitude()
let myLongitude = self.getLongitude()
let myDetail = self.myDetail
let userLocation = UserLocation(context: self.moc)
userLocation.id = UUID()
userLocation.date = myDate
userLocation.time = myTime
userLocation.latitude = myLatitude
userLocation.longitude = myLongitude
userLocation.detail = myDetail
try? self.moc.save()
}
}