ios - 无法将用户添加到现有的 Parse.com 角色

标签 ios swift parse-platform

使用这段代码,我尝试将用户添加到现有的 Parse.com 角色“禁止”:

 var roleACL = PFACL()
 var role = PFRole(name: "banned", acl:roleACL)
 role.users.addObject(userObject) // This should add user
 role.saveInBackground()

我收到错误 137 提供了具有唯一值的字段的重复值(代码:137,版本:1.6.1)

我猜它试图重新创建角色。 但是,请在 https://www.parse.com/docs/ios_guide#roles-security/iOS 处形成文档我不知道如何将用户添加到现有角色。

最佳答案

得到解决方案。上面的误导性代码(如 Parse.com 网站上所示)尝试重新创建角色。 正确的代码是:

var queryRole = PFRole.query() // You need to get role object
queryRole.whereKey("name", equalTo:"banned")
queryRole.getFirstObjectInBackgroundWithBlock() {
(roleObject: PFObject!, error: NSError!) -> Void in
if error == nil {

      // Assign user to banned role
      var roleToAddUser = roleObject as PFRole
      roleToAddUser.users.addObject(userObject)
      roleToAddUser.saveInBackground()

     }
}

关于ios - 无法将用户添加到现有的 Parse.com 角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28724710/

相关文章:

c# - 在使用 IntPtr 构造函数进行单元重用时设置 Xamarin UITableViewCellStyle

IOS - UITableView 单元格,单击单元格内的 UIImageView 但停止调用 didSelectRowAtIndexPath

swift - 我如何根据条件创建一个可以是多个字符串之一的常量?

ios - 加载后设置图像大小

swift - 以编程方式创建的 UIPopoverPresentationController 填充屏幕

parse-platform - 如何在解析中查询 'Object' 类型字段。

ios - 在 View Controller segue 之间传递数据

ios - 如何使用 NSOperationQueue 发出同步请求?

ios - 在 IOS 上存储照片的最佳后端服务器

swift - 如何删除使用“findObjectsInBackgroundWithBlock”检索到的整个 [AnyObject] 数组?