Swift Core数据尝试填充时出错

时间:2015-11-02 17:47:30

标签: ios swift core-data

我是swift的新手并且遇到核心数据问题。

我的应用在尝试填充时崩溃了。我只有一个字段用于测试目的

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)")
    }
}

}

这是我得到的错误

  

2015-11-02 17:38:04.880 DinDins [2993:1252158] CoreData:错误:非法   尝试保存到从未打开过的文件。 "该   NSPersistentStoreCoordinator没有持久存储(未知)。它   无法执行保存操作。"。没有记录最后的错误。 2015年11月2日   17:38:04.885 DinDins [2993:1252158] *因未被捕获而终止应用   例外' NSInternalInconsistencyException',原因:'这   NSPersistentStoreCoordinator没有持久存储(未知)。它   无法执行保存操作。'   * 第一次抛出调用堆栈:(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:终止于   NSException(lldb)

类型的未捕获异常

提前致谢

--- 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


}

1 个答案:

答案 0 :(得分:0)

里卡多,尝试重置你的模拟器。打开模拟器,转到菜单 Simulator 并选择重置内容和设置