ios - 如何从解析数组中删除项目?

标签 ios swift parse-platform

在我的应用程序上有一个喜欢帖子的选项。我使用我分配给带有 .addTarget 的点赞按钮的这个函数将用户的 objectId 添加到一个数组中,该数组被计算以确定有多少点赞。我想知道如何从数组中删除一个名字,就像有人想对帖子点赞一样。

func like(sender: AnyObject) {

    var buttonPosition: CGPoint = sender.convertPoint(CGPointZero, toView: self.table)

    var indexPath: NSIndexPath = self.table.indexPathForRowAtPoint(buttonPosition)!

    var postsQuery = PFQuery(className: "Post")

    postsQuery.whereKey("message", equalTo: messages[indexPath.row])

    postsQuery.findObjectsInBackgroundWithBlock { (posts, error) -> Void in
        if let posts = posts {
            for post in posts {
                post.addUniqueObject(PFUser.currentUser()!.objectId!, forKey: "likers")
                println(self.likesArray)
                post.saveInBackground()
                self.table.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
            }
        }
    }

}

最佳答案

当您使用 addUniqueObject:forKey: 添加到数组时,您可以使用 removeObject:forKey: 从数组中删除然后保存。

关于ios - 如何从解析数组中删除项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32544536/

相关文章:

cocoa - 检测您的 cocoa swift 应用程序运行的位置

swift - 解析... query.getObjectInBackgroundWithId

javascript - 解析云: Unable to return value of query of max value in a column

javascript - 如何在没有for循环的情况下在JavaScript中显示数组?

javascript - ionic 菜单创建自己的类型或更改现有的动画和行为

arrays - Swift中基于最后一个字符的字符串排序

ios - AWS - 通过用户池进行 Cognito 登录和 Cognito 身份验证 [iOS]

ios - 在 Swift 4 中移动 UIBezierPath 笔划的最佳方式是什么?

ios - 更改 UILabel 文本仅适用于 viewDidLoad()

iphone - 如何在 iPhone 中获取设备位置名称?