Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 保存google将对象放置到核心数据-以NSException error类型的未捕获异常终止_Ios_Swift_Core Data_Autocomplete_Fatal Error - Fatal编程技术网

Ios 保存google将对象放置到核心数据-以NSException error类型的未捕获异常终止

Ios 保存google将对象放置到核心数据-以NSException error类型的未捕获异常终止,ios,swift,core-data,autocomplete,fatal-error,Ios,Swift,Core Data,Autocomplete,Fatal Error,我试图使用CoreData保存和检索用户通过使用自动完成小部件在Google地图上标记的标记。但是,我不断收到一个“libc++abi.dylib:以NSException类型的未捕获异常终止”错误,我不确定这是为什么或是什么意思?当我尝试将对象存储到核心数据时,就会发生这种情况 以下是相关代码: func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place:

我试图使用CoreData保存和检索用户通过使用自动完成小部件在Google地图上标记的标记。但是,我不断收到一个“libc++abi.dylib:以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中,但我最终得到了同样的致命错误

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

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


这个错误意味着什么?我该如何克服它

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

我现在已经解决了这个问题,这是相当愚蠢的,但很容易犯这样的错误供他人参考。如果在创建xcdatamodel后重命名它,请不要忘记在声明容器的Appdelegate中更改它。因此“let container=NSPersistentContainer(name:“您重命名的文件”)”,否则会出现上述错误

这是ViewController。我将更新帖子以显示AppDelegate方法。我使用的是最新版本的Xcode和Swiftoh gosh,感谢您的提问,因为事实证明我忘记了更改容器名称以匹配我的xcdatamodel,因为我在创建之后重命名了它。。。。