0
votes

I am making a simple login screen for my app. Initially when i set up PFObject and PFUser to save in background it was working, all of a sudden I added a few more lines of codes and boom, it stops working with the following error:

2015-10-24 04:49:09.101 ParseStarterProject-Swift[936:44671] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The class PFUser must be registered with registerSubclass before using Parse.' * First throw call stack:

My code is very simple:

import UIKit
import Parse

class ViewController: UIViewController, UIApplicationDelegate {

    //registration screen VARIABLES

    var user = PFUser()
    //Password
    @IBOutlet weak var password: UITextField!
    //UserName
    @IBOutlet weak var userName: UITextField!
    //Email
    @IBOutlet weak var userEmailAddress: UITextField!

    //registration Screen METHODS

    //Facbook
    @IBAction func facebookRegistration(sender: AnyObject) {
    }
    //Twitter
    @IBAction func twitterRegistration(sender: AnyObject) {
    }
    //Email
    @IBAction func emailRegistartion(sender: AnyObject)
    {
    //Check if any fields are nil
    if userEmailAddress.text == "" || userName.text == "" || password.text == ""
    {
        //provide and alert
        self.alert("oops", yourMessage: "looks like you are missing some fields", yourPrefferredStyle: UIAlertControllerStyle.Alert, actionTitle: "ok", alertStyle: UIAlertActionStyle.Default)
        self.activityIndicator(frame: 0, frame: 0, frame: 50, frame: 50, indicatorViewStyle: .White)
    }
        //implement email confirmation alert
    else{
        self.createUser(userName.text, password: password.text, email: userEmailAddress.text)

    }
}

//Sign In 

@IBAction func signInButton(sender: AnyObject) {
}


//THIS IS A GENERIC FUNCTION TO CREATE A PFUSER
func createUser (username: String!, password: String!, email: String!)
{
    let user = PFUser()
    user.username = username
    user.password = password
    user.email = email
    user.signUpInBackgroundWithBlock { (saved: Bool, error:NSError?) -> Void in
        if let error = error {
            _ = error.userInfo["error"] as? NSString
}
        else
        {
            self.alert("Registered!", yourMessage: "You have successfully registered, please check your email for verification.", yourPrefferredStyle: UIAlertControllerStyle.Alert, actionTitle: "Sweet", alertStyle: UIAlertActionStyle.Default)
        }
                            }

}

//THIS IS THE GENRIC ALERT FUNCTION

func alert (alertTitle: String?, yourMessage: String?, yourPrefferredStyle:UIAlertControllerStyle, actionTitle: String?, alertStyle: UIAlertActionStyle)
{
    let alert = UIAlertController(title: (alertTitle), message:(yourMessage), preferredStyle:(yourPrefferredStyle))
    alert.addAction((action: UIAlertAction(title: (actionTitle), style: (alertStyle), handler: { (action) -> Void in
        self.dismissViewControllerAnimated(true, completion: nil)})))
    self.presentViewController(alert, animated: true, completion: nil)
}

//THIS IS A GENEREIC LOADING INDICATION ANIMATION

func activityIndicator (frame x: CGFloat?, frame y: CGFloat?, frame Width: CGFloat?, frame height: CGFloat?, indicatorViewStyle: UIActivityIndicatorViewStyle)
{
  var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
    activityIndicator.center = self.view.center
    activityIndicator.hidesWhenStopped = true
    activityIndicator.activityIndicatorViewStyle = indicatorViewStyle
    view.addSubview(activityIndicator)
    activityIndicator.startAnimating()
    UIApplication.sharedApplication().beginIgnoringInteractionEvents()

}

As you can see, I have created my own function for creating a PFuser so that I can just call a function everytime a user inputs new credentials an hits register... but its not working. Hope someone can help!

1
Which are the few lines of code? The user var? - Wain
what do you mean? there doesnt seem to be a problem with the code as I have commented out literally all different chunks and even the whole project an i am still getting this error... - Arbab Rizvi

1 Answers

0
votes

You need to call the setup method in your application delegate.

[Parse setApplicationId:@"xxx" clientKey:@"xxx"];

https://parse.com/apps/quickstart#parse_data/mobile/ios/native/new