Reputation: 975
When I am querying for objects from Parse, I get the error: [Error]: bad characters in classname: (null). Here is my querying function:
func findEmployeeForLoggedInUser(completion: (array: [PFEmployee], error: String?) -> Void) {
var query = PFQuery()
query.whereKey("employerId", equalTo: PFUser.currentUser()!.objectId!)
query.findObjectsInBackgroundWithBlock { (results, error) -> Void in
var employeeArray = results as? [PFEmployee]
if let error = error {
let errorString = error.userInfo?["error"] as? String
if let objects = employeeArray {
completion(array: objects, error: errorString)
} else {
completion(array: [], error: errorString)
}
} else {
if let myObjects = employeeArray {
for object in myObjects {
let object = object as PFEmployee
}
}
completion(array: employeeArray!, error: nil)
}
}
}
When I actually want to query for objects, I call the function in a separate file:
networking.saveEmployee(employee, completion: { (error) -> Void in
if error == nil {
var alert = UIAlertController(title: "Success!", message: "Your employee was saved!", preferredStyle: .Alert)
var alertAction = UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
})
alert.addAction(alertAction)
self.presentViewController(alert, animated: true, completion: nil)
} else {
var alert = UIAlertController(title: "Error", message: "\(error)", preferredStyle: .Alert)
var alertAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Cancel, handler: nil)
alert.addAction(alertAction)
self.presentViewController(alert, animated: true, completion: nil)
}
})
I call the function in the viewDidLoad method. networking
is an instance of my Networking class where the querying function was originally declared. What does this error mean, and what am I doing wrong?
EDIT: HOW PFEMPLOYEE IS BEING CREATED
class PFEmployee: PFObject, PFSubclassing {
override class func initialize() {
self.registerSubclass()
}
class func parseClassName() -> String {
return "Employee"
}
@NSManaged var name: String?
@NSManaged var jobDesc: String?
@NSManaged var numberOfPoints: Int
@NSManaged var education: String?
@NSManaged var birthday: String?
@NSManaged var employerId: String?
@NSManaged var image: PFFile?
@NSManaged var email: String
@NSManaged var commentary: String?
}
Upvotes: 3
Views: 598
Reputation: 62676
PFQuery needs to be instantiated with a class name:
var query = PFQuery(className: "PFEmployee")
Assuming the class is called PFEmployee in the parse data.
Upvotes: 1