在我正在创建的应用程序中,用户在地图上放置了一个图钉并保存它。销的坐标保存为CLLocationCoordinate2D
坐标。这是我的代码-
@IBAction func saveItem(_ sender: AnyObject?) {
let itemName = itemNameTextField.text!
let itemDescription = itemDescriptionLabel.text!
let itemLocation = itemLocationTextView.text!
let point = dropPin.coordinate
if itemName == "" {
let alertController = UIAlertController(title: "The Item Name!", message:"You have not entered an item name. Please enter a name before saving.", preferredStyle: UIAlertControllerStyle.alert)
let OKAction = UIAlertAction(title: "Got It!", style: UIAlertActionStyle.default, handler: nil)
alertController.addAction(OKAction)
self.present(alertController, animated: true, completion: nil)
}
if itemDescription == "" {
let alertController = UIAlertController(title: "The Description!", message:"You have not entered a description for your item. Please enter a description before saving.", preferredStyle: UIAlertControllerStyle.alert)
let OKAction = UIAlertAction(title: "Got It!", style: UIAlertActionStyle.default, handler: nil)
alertController.addAction(OKAction)
self.present(alertController, animated: true, completion: nil)
}
if itemLocation == "" {
let alertController = UIAlertController(title: "The Item Location!", message:"You have not entered the location of your item. Please do so before saving. Marking the loction on teh map is not necessary, but it is recommended.", preferredStyle: UIAlertControllerStyle.alert)
let OKAction = UIAlertAction(title: "Got It!", style: UIAlertActionStyle.default, handler: nil)
alertController.addAction(OKAction)
self.present(alertController, animated: true, completion: nil)
}
else{
item = itemData(itemName:itemName, itemDescription:itemDescription, itemPlace:itemLocation, mapPoint:point)
print("Item name: \(itemName), Item Description: \(itemDescription), Item Location: \(itemLocation)")
self.performSegue(withIdentifier: "saveUnwind", sender: self)
}
}
但是,当用户保存时,我收到这样的错误 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue encodeWithCoder:]: unrecognized selector sent to instance 0x170c552d0'
。为什么我会收到此错误?我如何解决它?谢谢!