Swift xcode:缺少参数标签';地址:' ;;随时待命

Swift xcode:缺少参数标签';地址:' ;;随时待命,swift,xcode,Swift,Xcode,我对斯威夫特很陌生 谁被按入应用程序以删除照片和要删除的评论 我从以下网址得到信息: self.comments.remove(post[“message”]作为!字符串) self.imageFile.remove(将[“imageFile”]发布为!PFFile) 调用中缺少参数标签“at:” 删除功能: @IBAction func remove(_ sender: Any) { let query = PFQuery(className: "Post") quer

我对斯威夫特很陌生

谁被按入应用程序以删除照片和要删除的评论

我从以下网址得到信息:

self.comments.remove(post[“message”]作为!字符串) self.imageFile.remove(将[“imageFile”]发布为!PFFile)

调用中缺少参数标签“at:”

删除功能:

   @IBAction func remove(_ sender: Any) {

    let query = PFQuery(className: "Post")
    query.whereKey("username", equalTo: PFUser.current()?.username)
    query.findObjectsInBackground(block: { (object, error) in

        if let posts = object {
            for post in posts{
                print(posts)

                let objectIdVar = post["objectId"] as! String
                post.remove(forKey: "objectIdVar")
                self.comments.remove(post["message"] as! String)
                self.imageFile.remove(post["imageFile"] as! PFFile)
                self.tableView.reloadData()

}

            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    })
}

有人能告诉我我做错了什么,我怎么做才是对的吗


感谢您的帮助

数组上没有将要删除的内容作为参数的
删除
方法,您只能删除特定索引处的元素:

self.comments.remove(at: self.comments.index(of: post["message"] as! String)!)

如果您想要这样的<代码>删除< /代码>函数,请考虑使用<代码> SET>代码>,或者编写自己的扩展名:

extension Array where Element : Equatable {
    @discardableResult
    mutating func remove(element: Element) -> Element? {
        guard let i = self.index(of: element) else { return nil }
        return self.remove(at: i)
    }
}

查看
remove(at:)
函数的签名:

您只需在通话中添加“at:”,如下所示:

self.comments.remove(at: /*Have an Int here*/)
self.imageFile.remove(at: /*Have an Int here*/)

确保注释和imageFile是可变数组,以便
remove(at:)
工作。

不相关,但不要在循环的每个迭代中重新加载表视图。那太贵了。最好使用
tableView.deleteRows
来制作动画。非常感谢,这比我想象的要难。如何正确实现此功能?您可以使用第二个代码段中的扩展名,或者使用一个
Set
,它具有所需的
remove
方法@Daniel.Pi have,self.comments.remove(post[“message”]as!String)self.imageFile.remove(post[“imageFile”]as!PFFile)by self.comments.remove(at:self.comments.index(of:post[“message”]as!String)!)self.imageFile.remove(at:self.imageFile.index(of:post[“imageFile”]as!PFFile)!)已替换。我将消息发送到线程1:致命错误:在展开可选线程时意外发现nilvalue@Daniel.P然后,要么字典的值与指定的类型不匹配,要么数组中不存在元素。他不知道要删除哪些单元格内容。我想。每个单元格都是一张照片和一条评论。在删除时,谁在单元格中单击以删除单元格的内容,或者更好地删除整个单元格的内容。我在第一个问题中添加了一个屏幕截图。我可能搞错了
self.comments.remove(at: /*Have an Int here*/)
self.imageFile.remove(at: /*Have an Int here*/)