gpt4 book ai didi

ios - 尝试填充时出现 Swift Core 数据错误

转载 作者:搜寻专家 更新时间:2023-11-01 05:38:48 25 4
gpt4 key购买 nike

我是 swift 新手,遇到核心数据问题。

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

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

提前致谢

---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,尝试重置你的模拟器。打开模拟器,转到模拟器菜单并选择重置内容和设置

关于ios - 尝试填充时出现 Swift Core 数据错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33483735/

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