gpt4 book ai didi

ios - 在核心数据 swift ios 中使用未解析的标识符 "Model"

转载 作者:行者123 更新时间:2023-11-28 06:05:59 24 4
gpt4 key购买 nike

我正在将数据保存在一个名为 Forms 的实体中,但是当我调用 Forms 时它给我错误一切都很好,但突然出现错误,现在让我很恼火。我不知道为什么即使没有任何语法错误。

use of unresolved identifier "Forms"

这是我的代码

import UIKit
import CoreData

@available(iOS 11.0, *)
class ViewViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// var getAddController : AddViewController = AddViewController()
var fName : String?
var fDesc : String?
var formName : String?
var results : [NSManagedObject] = []

@IBOutlet weak var menu: UIBarButtonItem!
@IBOutlet weak var viewTableView: UITableView!

var manageObjectContext: NSManagedObjectContext!
var eventArray = [Forms]() // Where **Forms** is an model name

let appDel = UIApplication.shared.delegate as! AppDelegate
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Forms")
//var eventRequest: NSFetchRequest<Forms> = Forms.fetchRequest()

func loadSaveData() {
let eventRequest: NSFetchRequest<Forms> = Forms.fetchRequest()
do{
eventArray = try manageObjectContext.fetch(eventRequest)
self.viewTableView.reloadData()
}catch
{
print("Could not load save data: \(error.localizedDescription)")
}
}

...
table view methods here
...

func moveToEdit() {
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle : nil)
let desController = mainStoryBoard.instantiateViewController(withIdentifier: "EditViewController") as! EditViewController
let newFrontViewController = UINavigationController.init(rootViewController:desController)
revealViewController().pushFrontViewController(newFrontViewController, animated: true)
}

override func viewDidLoad() {
super.viewDidLoad()

menu.target = revealViewController()
menu.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

let context = appDel.persistentContainer.viewContext
results = try! context.fetch(request) as! [NSManagedObject]

viewTableView.delegate = self
viewTableView.dataSource = self
viewTableView.reloadData()

request.returnsObjectsAsFaults = false

manageObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
self.loadSaveData()
}
}

更新

var eventArray = [Forms]() 更改为 var 事件数组:[NSManagedObject] = []

我在 func loadSaveData() 中遇到错误

 let eventRequest: NSFetchRequest<Forms> = Forms.fetchRequest()

use of undeclared type "Forms"

最佳答案

1.将您的 eventArray 类型更改为 NSManagedObject

var eventArray : [NSManagedObject] = []

2. loadSaveData() 方法的更新代码。

func loadSaveData()  {
let eventRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Forms")
do{
eventArray = try manageObjectContext.fetch(eventRequest) as! [NSManagedObject]
self.viewTableView.reloadData()
}catch
{
print("Could not load save data: \(error.localizedDescription)")
}
}

关于ios - 在核心数据 swift ios 中使用未解析的标识符 "Model",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48220196/

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