Swift 5如果[[object]]的名称包含另一个数组的一个或多个值

时间:2019-05-01 12:50:06

标签: arrays swift sorting

需要语句帮助,我有 [[object]?] ,其中包含 name 字段(下面的结构)以及具有类型的数组

let _object = [[object]]

如果 _object 包含 types 数组

中的一个或多个值,我想返回true / false

类型数组

let types = ["jewelry_store", "liquor_store", "shopping_mall", "clothing_store", "store"]

_对象表示

enter image description here

我只有var _object = places.map{$0.typePlaceSet} //[[object]?]

1 个答案:

答案 0 :(得分:1)

从每个数组创建两个集合,看看它们是否相交

let typesSet: Set<String> = ["jewelry_store", "liquor_store", "shopping_mall", "clothing_store", "store"]

let objectSet: Set<String> = _object.flatMap { $0.name } 

return !objectSet.isDisjoint(with typeSet)