gpt4 book ai didi

xcode - NSFetchRequest 找不到 NSEntityDescription

转载 作者:行者123 更新时间:2023-11-28 10:01:49 26 4
gpt4 key购买 nike

我知道这是其他问题的重复,但我已经按照这些问题的答案进行操作,但仍然遇到相同的错误。

我认为错误是因为代码在数据还没有保存时​​就试图获取数据(保存数据有延迟,因为我是从 Parse 获取数据的)。有什么想法吗?

我得到的确切错误是:

 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSFetchRequest could not locate an NSEntityDescription for entity name 'emailStatus''

-

import UIKit
import CoreData

class RegisterEmail: UIViewController {

var test1: Bool?

override func viewDidLoad() {
super.viewDidLoad()

}

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

override func shouldPerformSegueWithIdentifier(identifier: String!, sender: AnyObject!) -> Bool {
if identifier == "passEmail" {

var query = PFUser.query()
query.getObjectInBackgroundWithId("vFu93HatwL") {
(User: PFObject!, error: NSError!) -> Void in
if error == nil {
NSLog("%@", User)

var checkEmail = User["emailVerified"] as Bool

println(checkEmail)

var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)

var context:NSManagedObjectContext = appDel.managedObjectContext!

var newEmail = NSEntityDescription.insertNewObjectForEntityForName("Email", inManagedObjectContext: context) as NSManagedObject

newEmail.setValue(checkEmail, forKey: "emailStatus")

context.save(nil)

println (newEmail)

println("Object Saved")

} else {
NSLog("%@", error)
}


}


var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)

var context:NSManagedObjectContext = appDel.managedObjectContext!

var request = NSFetchRequest(entityName: "emailStatus")

request.returnsObjectsAsFaults = false

var results: NSArray = context.executeFetchRequest(request, error: nil)!

if(results.count > 0)
{
var res = results [0] as NSManagedObject

test1 = res.valueForKey("emailStatus") as Bool

}


if (test1 == false) {

let alert = UIAlertView()
alert.title = "Error"
alert.message = "The email you have provided has not been verified."
alert.addButtonWithTitle("Dismiss")
alert.show()

return false
}

else {

return true
}
}

// by default, transition
return false
}
}

最佳答案

来自 op:“...一切都在数据库文件中设置。实体称为电子邮件,属性为 emailStatus”

然而您尝试获取一个实体 emailStatus,您可能需要在其中接收电子邮件。
var request = NSFetchRequest(entityName: "emailStatus")

“打字错误”

然后获取正确的实体:'email'
var request = NSFetchRequest(entityName: "email")

关于xcode - NSFetchRequest 找不到 NSEntityDescription,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27536503/

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