2

I'm new with swift and got a problem with core data.

My app crashes when trying to populate. I just have 1 field as for testing purposes

import UIKit
import SwiftyJSON
import CoreData

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    seedRestaurantList()
    fetch()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func fetch() {
    let moc = DataController().managedObjectContext
    let nameFetch = NSFetchRequest(entityName: "RestaurantList")

    do {
        let fetchedName = try moc.executeFetchRequest(nameFetch) as! [RestaurantList]
        print(fetchedName.first!.name!)

    } catch {
        fatalError("merda again: \(error)")
    }
}
func seedRestaurantList () {
    let moc = DataController().managedObjectContext


    let entity = NSEntityDescription.insertNewObjectForEntityForName("RestaurantList", inManagedObjectContext: moc) as! RestaurantList

    entity.setValue("teste", forKey: "name")


    do {
        try moc.save()


    } catch {
        fatalError("deu merda: \(error)")
    }
}

}

This is the error that I get

2015-11-02 17:38:04.880 DinDins[2993:1252158] CoreData: error: Illegal attempt to save to a file that was never opened. "This NSPersistentStoreCoordinator has no persistent stores (unknown). It cannot perform a save operation.". No last error recorded. 2015-11-02 17:38:04.885 DinDins[2993:1252158] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores (unknown). It cannot perform a save operation.' * First throw call stack: (0x236c585b 0x3503adff 0x2346da89 0x2346dc95 0x2346de2d 0x2347710f 0x1249d03 0x12534fb 0x23468ef1 0x233b31f3 0x233b3223 0x233d615b 0x9cff0 0x9c360 0x9c400 0x277f9f55 0x278b6c4f 0x278b6b45 0x278b5ef1 0x278b5b27 0x278b577d 0x278b56f7 0x277f5cc3 0x270bdb05 0x270b9201 0x270b9091 0x270b85b1 0x270b8263 0x270b1a1f 0x23688091 0x23686387 0x235d90f9 0x235d8ecd 0x27867607 0x278622dd 0x9fde0 0x35788873) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Thanks in advance

---RestaurantList+CoreDataProperties.swift

import Foundation
import CoreData

extension RestaurantList {

    @NSManaged var name: String?

}

---RestaurantList.swift

import Foundation
import CoreData

class RestaurantList: NSManagedObject {

// Insert code here to add functionality to your managed object subclass


}
Ricardo Alves
  • 642
  • 2
  • 13
  • 34

1 Answers1

0

Ricardo, try reseting your simulator. Open the Simulator, go to menu Simulator and select Reset content and Settings