gpt4 book ai didi

ios - 将谷歌放置对象保存到核心数据 - 因未捕获的 NSException 类型异常错误而终止

转载 作者:行者123 更新时间:2023-11-30 12:47:57 24 4
gpt4 key购买 nike

我正在尝试使用 CoreData 来保存和检索用户通过使用自动完成小部件在 Google map 上标记的标记。但是我不断收到 'libc++abi.dylib: termination with uncaught exception of type NSException' 错误,并且不确定为什么或这意味着什么?当我尝试将对象存储到核心数据中时,就会发生这种情况。

相关代码如下:

    func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
self.place = place
let camera = GMSCameraPosition.camera(withLatitude: place.coordinate.latitude, longitude: place.coordinate.longitude, zoom: 15.0)
self.vwGMap.camera = camera
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(place.coordinate.latitude, place.coordinate.longitude)
marker.title = place.name
marker.snippet = place.formattedAddress
marker.map = self.vwGMap
marker.icon = GMSMarker.markerImage(with: UIColor.blue)
marker.tracksViewChanges = true
self.dismiss(animated: true, completion: nil)
print("Place name: ", place.name)
print("Place address: ", place.formattedAddress)
print("Place placeID: ", place.placeID)
print("Place attributions: ", place.attributions)
print("Place Coordinate:", place.coordinate)
//The printing only happens in the terminal

let newPlaceName = place.name
self.newPlaceName = place.name
let newPlaceAddress = place.formattedAddress
self.newPlaceAddress = place.formattedAddress!
let newPlacePlaceID = place.placeID
self.newPlacePlaceID = place.placeID

let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let newPlace = NSEntityDescription.insertNewObject(forEntityName: "StoredPlace", into: context)

newPlace.setValue(newPlaceName, forKeyPath: "name")
newPlace.setValue(newPlaceAddress, forKeyPath: "address")
newPlace.setValue(newPlacePlaceID
, forKeyPath: "placeID")

do
{
try context.save()
print("SAVED")
}
catch
{
//PROCESS ERROR
}


}

也许我应该将 let appDelegate 等放入 viewDidLoad 中,但我最终得到了同样的 fatal error 。

我在 StoredPlace 实体中将名称、地址、placeID 设置为“String”类型的属性。

有关错误的更多信息: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“+entityForName:nil不是搜索实体名称“StoredPlace”的合法 NSManagedObjectContext 参数*** 首先抛出调用堆栈:

这个错误是什么意思以及如何解决它?

最佳答案

你的核心数据方法在哪里?在此 ViewController 中还是在 AppDelegate 中?

关于ios - 将谷歌放置对象保存到核心数据 - 因未捕获的 NSException 类型异常错误而终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41382103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com