ios - [错误] : bad characters in classname: (null)

标签 ios swift parse-platform

当我从 Parse 查询对象时,我收到错误:[错误]:类名中的错误字符:(空)。这是我的查询函数:

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)
        }
    }
}

当我真正想要查询对象时,我在一个单独的文件中调用该函数:

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)
        }
    })

我在 viewDidLoad 方法中调用函数。 networking 是我的 Networking 类的一个实例,其中最初声明了查询函数。这个错误是什么意思,我做错了什么?

编辑:如何创建 PFEMPLOYEE

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?
}

最佳答案

PFQuery 需要用一个类名来实例化:

var query = PFQuery(className: "PFEmployee")

假设类在解析数据中被称为 PFEmployee。

关于ios - [错误] : bad characters in classname: (null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30814421/

相关文章:

ios - 获取时如何初始化PFObject子类?

iOS - UIView 不显示在 UIStackView 内

swift - 如何解决 Swift 中的类名冲突

android - 在代号中,一个组合框文本被截断

ios - 如何在 iOS Swift 4 中的视频上添加图像水印?

ios - Collection View 在 cell.viewWithTag(100) 上崩溃

swift - 使用指针解析检索 PFObject

ios - 解析分页 loadNextPage 第二页加载两次

ios - Xcode 6.1 - 无法打开 Nib,因为您无权查看它

ios - 问答应用程序,当用户使用分段控件选择 A 或 B 时如何加 1