如何在[Type:[Type]]()

时间:2019-06-26 19:29:57

标签: swift dictionary swift4

我有一个包含多个值的字典,我想通过它筛选出零个值。字典的类型是:

var dic = [Int: [String]]()

字典是:

var dic = [218: ["A", "B", "C",""],216: ["Q", "", "W",""]]

//remove the empty values
let filter = dic.filter({ !$0.value.isEmpty})
print(filter)

它返回与nil值相同的字典值,应将其删除。

1 个答案:

答案 0 :(得分:1)

似乎您需要从""过滤内部数组,该数组不是nil,而是表示您需要的空字符串

let filter = dic.mapValues { $0.filter { $0 != "" } }