arrays - Swift - 从字典中删除一个数组

标签 arrays swift uitableview dictionary

我试图从字典中的数组中删除一个元素,但是当我从 tableview 中删除它时,该值并没有从字典中删除。我尝试删除数组的方式有误吗?

marker.buttonAction["button actions array"]?.remove(at: indexPath.row)

//Function to remove array from dictionary and tableview.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {

    if editingStyle == .delete {

        if let marker = markUpPlist.arrayObjects.filter({$0.tagClip == currentSelectedMarker}).first {

            print(marker.buttonAction["button actions array"]?[indexPath.row].action)

                marker.buttonAction["button actions array"]?.remove(at: indexPath.row)
                tableView.beginUpdates()
                tableView.deleteRows(at: [indexPath], with: .automatic)
                tableView.endUpdates()
        }
    }
}

//Variable which stores the dictionary
var buttonAction : [String: [ButtonAction]] = [:]

//ButtonAction array
class ButtonAction: Codable {
var action: String
var array_linked_of_buttons: [[String:String]]

init(action: String, array_linked_of_buttons: [[String:String]]) {
 self.action = action
 self.array_linked_of_buttons = array_linked_of_buttons
  }
}

最佳答案

答案是我忘记在删除数据后重新保存数据。代码工作正常,如果这对其他人有帮助,我将离开这个问题。

关于arrays - Swift - 从字典中删除一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54244981/

相关文章:

ios - UITableViewCell 不尊重 shouldIndentWhileEditing = NO?

ios - 如何以只读方式设置 UICollectionViewCell 的属性

php - 删除数组中相邻的相似值

ruby - 如何在 Ruby 的数组中找到唯一元素以及每个元素的出现次数

javascript - AngularJS - 显示 ng-repeat 多数组

ios - Swift 中的 CFDictionaryRef 问题

ios - 如何在 Swift(iOS、Xcode)中将 NSDictionary 转换为 Json 字符串?

c - 我怎么知道数组中的元素是否存在?

ios - 低功耗模式下的 UNNotificationAction 处理程序

iOS - 禁用 UITableViewCell 的向右或向左滑动