I'm a newbie to Swift and xCode so apologies if some of my terminology is incorrect.
I've just started learning CoreData and am attempting to produce a basic function where users can create a 'location.'
I set up the data model with the attributes name (type = string), latitude (type = double) and longitude (type = double).
I've set up a TableViewController (which is working fine) with a segue to another Controller which is set up to enable people to enter a name, latitude and longitude.
As far as I can tell, everything is set up correctly except for the two lines of code which read the text fields I connected to the Latitude and Longitude outlet. This code is contained in the AddLocationController.
Any help would be appreciated!
@IBOutlet var nameTextField:UITextField!
@IBOutlet var latitudeTextField:UITextField!
@IBOutlet var longitudeTextField:UITextField!
@IBAction func save(sender: AnyObject) {
if let appDelegate = (UIApplication.shared.delegate as? AppDelegate) {
location = LocationMO(context: appDelegate.persistentContainer.viewContext)
location.name = nameTextField.text
// This is where the error occurs
location.latitude = latitudeTextField.text
location.longitude = longitudeTextField.text
print("saving data to context ...")
appDelegate.saveContext()
}
dismiss(animated: true, completion: nil)
}
}