以下代码检查Parse以查看是否已验证电子邮件地址。我能够从Core Data中检索对象ID(我将其保存在以前的视图控制器中)但是当涉及query.getObjectInBackgroundWithId(userID)
时,userID
由于某种原因nil
。我收到错误:
错误:没有与查询匹配的结果(代码:101,版本:1.6.0)
import UIKit
import CoreData
class HomePage: UIViewController{
@IBOutlet var emailMessage: UILabel!
//var userID: String!
override func viewDidLoad() {
super.viewDidLoad()
var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var context:NSManagedObjectContext = appDel.managedObjectContext!
var request = NSFetchRequest(entityName: "Users")
request.returnsObjectsAsFaults = false
var results: NSArray = context.executeFetchRequest(request, error: nil)!
var res = results [0] as NSManagedObject
var userID = res.valueForKey("userID") as String
println (userID) //Correct ID is retrieved here
var query = PFQuery(className:"User")
query.getObjectInBackgroundWithId(userID) { //ID becomes nil
(email: PFObject!, error: NSError!) -> Void in
if error == nil {
let checkEmail = email["emailVerified"] as Bool
if (checkEmail != true)
{
self.emailMessage.hidden = false
}
else
{
self.emailMessage.hidden = true
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:2)
答案 1 :(得分:2)
解析中的User
表(以及所有其他解析管理的类)以下划线为前缀,因此您应该修复此行:
var query = PFQuery(className:"_User")