gpt4 book ai didi

swift - 如何删除 swift 3 中值为空的字典的键

转载 作者:搜寻专家 更新时间:2023-10-31 22:10:55 26 4
gpt4 key购买 nike

您好,我需要删除没有值的字典键。我尝试了很多代码但没有用。我只需要带有具有值的键的字典,我需要在 swift 3 中完成

["H": [], "X": [], "D": ["D1\r\n\r\n"], "J": ["J1\r\n"], "I": [], "M": [], "Z": [], "S": [], "A": ["A2"], "C": ["C2\r\n\r\n"], "N": [], "Y": [], "R": [], "G": [], "E": ["Emmm\r\n"], "V": [], "U": [], "L": [], "B": ["B2"], "K": ["King"], "F": [], "O": [], "W": [], "T": ["Test", "Test2"], "P": [], "Q": ["Queen"]]

最佳答案

我试过这段代码并为我工作。

var dict: [String: [Any]] = ["H": [], "X": [], "D": ["D1\r\n\r\n"], "J": ["J1\r\n"], "I": [], "M": [], "Z": [], "S": [], "A": ["A2"], "C": ["C2\r\n\r\n"], "N": [], "Y": [], "R": [], "G": [], "E": ["Emmm\r\n"], "V": [], "U": [], "L": [], "B": ["B2"], "K": ["King"], "F": [], "O": [], "W": [], "T": ["Test", "Test2"], "P": [], "Q": ["Queen"]]
for (key, value) in dict where value.isEmpty {
dict.removeValue(forKey: key)
}

关于swift - 如何删除 swift 3 中值为空的字典的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45809676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com