I'm subclassing PFUser
like this:
// 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"
}
}
Then I have a sign up view controller with some text fields and a button action which will sign up the user asynchronously to my Parse app:
// 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)
})
}
})
}
But then I get three compile errors that I don't know how to solve. I've just started using Swift with Parse so I'm a bit confused if I'm doing something wrong when I'm subclassing PFUser
or if it's something that have to do with the Parse SDK
Here are the errors I'm getting:
'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'
I've followed the Parse documentation guide on subclassing so I would appreciate any help here by you fellow developers!