在Swift中对PFUser进行子类化没有成员' signUpInBackgroundWithBlock'

时间:2015-10-21 18:44:35

标签: ios parse-platform swift2 xcode7 subclassing

我像这样继承PFUser

// User.swift
import UIKit
import Parse

class User: PFObject, PFSubclassing {
    override class func initialize() {
        struct Static {
            static var onceToken : dispatch_once_t = 0;
        }
        dispatch_once(&Static.onceToken) {
            self.registerSubclass()
        }
    }

    static func parseClassName() -> String {
        return "_User"
    }
}

然后我有一个注册视图控制器,其中包含一些文本字段和一个按钮操作,它将用户异步注册到我的Parse应用程序:

    // MARK: - Actions
    @IBAction func signUpAction(sender: UIButton) {
        var email = self.emailTextField.text
        var username = self.usernameTextField.text
        var password = self.passwordTextField.text

        // Run a spinner to show a task in progress
        var spinner: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(0, 0, 150, 150)) as UIActivityIndicatorView
        spinner.startAnimating()

        var newUser = User()

        // Sign up the user asynchronously
        newUser.signUpInBackgroundWithBlock({
            (succeed, error) -> Void in

            // Stop the spinner
            spinner.stopAnimating()
            if ((error) != nil) {
                var alert = UIAlertView(title: "Error", message: "\(error)", delegate: self, cancelButtonTitle: "OK")
                alert.show()

            } else {
                var alert = UIAlertView(title: "Success", message: "Signed Up", delegate: self, cancelButtonTitle: "OK")
                alert.show()
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Home") as! UIViewController
                    self.presentViewController(viewController, animated: true, completion: nil)
                })
            }
        })
    }

然后我得到三个编译错误,我不知道如何解决。我刚刚开始使用Swift和Parse,所以如果我在做PFUser的子类化时做错了,或者它有什么东西,我有点困惑与Parse SDK

有关

以下是我遇到的错误:

'SignUpViewController.User' does not conform to protocol 'PFSubclassing'

Value of type 'SignUpViewController.User' has no member 'signUpInBackgroundWithBlock'

Value of type 'User' has no member 'signUpInBackgroundWithBlock'

我已经关注了Parse documentation guide on subclassing,所以我很感谢你们的开发人员提供的任何帮助!

0 个答案:

没有答案