3

I am using Parse 1.7.5 and Swift 1.2 to create an account based application. I created a class User in which I have a property called user of type PFUser. The goal here is to implement all the Parse logic in this class so that in the future, if needed, I can easily change the backend without changing the logic in the rest of my application.

When I try to launch my application I get the following error in the console : The class PFUser must be registered with registerSubclass before using Parse.

I don't understand why I get this message as I am not subclassing the PFUser class.

Here is the source code from the User class :

import Foundation
import Parse

class User {
    var user: PFUser = PFUser()
    var location: PFGeoPoint?
    var timeLeft: Int?
    var error: NSError?

    // MARK: INIT

    init() {
        if let user = PFUser.currentUser() {
            self.user = user
        }
    }

    convenience init(username: String, password: String, email: String, firstName: String, lastName: String) {
        self.init()

        user.username = username
        user.password = password
        user.email = email
        user["firstName"] = firstName
        user["lastName"] = lastName
    }

    // MARK: USER INFO

    func getUserLocation() {
        PFGeoPoint.geoPointForCurrentLocationInBackground { (geoPoint: PFGeoPoint?, error: NSError?) -> Void in
            if let error = error {
                self.error = error
            } else {
                self.location = geoPoint
            }
        }
    }

    // MARK: LOGIN SIGNUP

    func loginWithUsername(username: String, password: String) -> Bool {
        PFUser.logInWithUsernameInBackground(username, password: password, block: { user, error in
            if let error = error {
                self.error = error
                print("\(error)")
            }
        })

        return isLoggedIn()
    }

    func logout() {
        PFUser.logOut()
    }

    func isLoggedIn() -> Bool {
        return user.isAuthenticated()
    }
}

Thank you for your help.

Jessy Naus
  • 54
  • 8

0 Answers0