如何检查用户名是否与解析一起使用?

时间:2015-06-18 17:50:18

标签: swift parse-platform

我有点不确定如何为此设置查询。我只能在php或javascript中找到解决方案。请帮忙!

1 个答案:

答案 0 :(得分:0)

这是代码片段,用于检查某个用户名是否已经在解析类中退出

/* Checks Is Username Already Exists
        Take - username
        Return - Bool (True/False) */

    func checkIsUserExists(username: String, completion: ((isUser: Bool?) -> Void)!) {

        var isPresent: Bool = false;

        let query: PFQuery = PFQuery(className: "your_class_name")
        query.whereKey("your_key", equalTo:username)

        query.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]?, error: NSError?) -> Void in

            if error == nil {
                if (objects!.count > 0) {
                    isPresent = true;
                }

            } else {
                // Log details of the failure
                println("Error: \(error) \(error!.userInfo!)")
            }

            completion(isUser: isPresent);
        }
    }