2016-12-29 5 views
0

CoreDataを使用して、ユーザーがオートコンプリートウィジェットを使用してGoogleマップにマークするマーカーを保存および取得しようとしています。しかし、私は 'libC++ abi.dylib:NSException型のキャッチされていない例外で終了する'というエラーメッセージを表示し続けています。私がオブジェクトをCore Dataに保存しようとすると起こります。ここでコアデータにgoogle placesオブジェクトを保存する - 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 
    } 


} 

は、おそらく私がのviewDidLoadにしましょうappDelegateなどを置くべきであるが、私は同じ致命的なエラーになってしまいます。

私はStoredPlaceエンティティで 'String'タイプの属性としてname、address、placeIDを設定しました。キャッチされない例外により「NSInvalidArgumentException」、理由に 終端アプリ:

、エラーの詳細を「+ entityForName:nilのエンティティ名を検索法的NSManagedObjectContextパラメータではありません 『StoredPlace』」 ***まずスローコールスタック:

このエラーは何を意味し、どうすれば回避できますか?

答えて

0

私はこれを今作業しましたが、それはむしろばかげていますが、FYIを他の人にするのは簡単な間違いです。 xcdatamodelを作成した後で名前を変更した場合は、Container = NSPersistentContainer(name: "YOUR RENAMED FILE") 'とすると、上記のエラーが表示されます。

0

あなたのコアデータメソッドはどこですか?このViewControllerまたはAppDelegateにありますか?

+0

これはViewControllerです。 AppDelegateメソッドを表示するように投稿を更新します。私はXcodeとSwiftの最新バージョンを使用しています。 –

+0

ああ、おかげでそれを聞いてくれてありがとう、私はそれを作成した後に名前を変更したので、私のxcdatamodelに合うようにコンテナ名を変更するのを忘れてしまった。 –

関連する問題