Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从parse.com检索IOS应用程序的PFusers时出现问题_Ios_Xcode_Swift_Parse Platform_Appdelegate - Fatal编程技术网

从parse.com检索IOS应用程序的PFusers时出现问题

从parse.com检索IOS应用程序的PFusers时出现问题,ios,xcode,swift,parse-platform,appdelegate,Ios,Xcode,Swift,Parse Platform,Appdelegate,我正在xCode Beta版的swift 2.0中构建一个IOS应用程序。我构建了一个自定义用户类,它是PFUser的子类,下面复制了该类的相关摘录 import UIKit class User: PFUser, Entity { // MARK: - Declare Field Variables @NSManaged var firstName : String @NSManaged var lastName : String //Several othe

我正在xCode Beta版的swift 2.0中构建一个IOS应用程序。我构建了一个自定义用户类,它是PFUser的子类,下面复制了该类的相关摘录

import UIKit

class User: PFUser, Entity {
    // MARK: - Declare Field Variables
    @NSManaged var firstName : String
    @NSManaged var lastName : String
    //Several other state variables follow in the same format

    ///initializing a new person
    init (firstName: String, lastName: String, password: String, email: String) {
        super.init()
        super.username = email
        super.password = password
        super.email = email
        //set initial key-value pairs for person
        self.firstName = firstName
        self.lastName = lastName

        // Special method to sign up new user
        super.signUp()
    }
    // Additional methods placed here

    // MARK: - Conformation to PFObjectSubclassing
    override class func initialize() {
        self.registerSubclass()
    }

    // MARK: - Conformation to Entity
    func saveToDatabase() {
        //Saves the new PFObject Asyncronously
        self.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
            if (success)    { print("User \(self.username) succesfully saved to database.") }
            else            { print(error) }
        }
    }
}
使用parse GUI,我验证用户是否已成功保存到数据库

我试图使用Appdelegate中编写的类检索数据,该类从Appdelegate调用,如下所示:

var examplePerson: User!

func funcThatIsCalled() {
    var query : PFQuery = PFUser.query()!
    var people = query.findObjects()
    self.examplePerson = people![0] as! User
}
User.registerSubclass()
        // Initialize Parse.
        Parse.setApplicationId("myAppID",
            clientKey: "MyClientKey")  
这将返回错误:

无法将“PFUser”0x108326490类型的值强制转换为“MyPersonalApp.User”0x108323f80

将User.registerSubclass添加到Appdelegate中,如下所示:

var examplePerson: User!

func funcThatIsCalled() {
    var query : PFQuery = PFUser.query()!
    var people = query.findObjects()
    self.examplePerson = people![0] as! User
}
User.registerSubclass()
        // Initialize Parse.
        Parse.setApplicationId("myAppID",
            clientKey: "MyClientKey")  
导致错误的原因:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因是:“类PFUser必须在使用Parse之前向registerSubclass注册。”

解决了这个问题:

PFUser.query()
应该是

User.query()