Set集合操作
var set_list:Set = ["hello","world","swift"]
//个数
print(set_list.count)
//插入
set_list.insert("ios")
print(set_list)
//包含
let tmp = set_list.contains("ios")
print(tmp)
//删除
set_list.remove("ios")
print(set_list)
//删除所有
//set_list.removeAll()
//print(set_list)
let data:Set = ["iphone","android","ios1","swift"]
//2个set合并
//var newS = set_list.union(data)
//print(newS)
//返回2个set中想通的数据
var news1 = set_list.intersection(data)
print(news1)
//返回2个set中之前不通的数据
var news2 = set_list.subtracting(data)
print(news2)
var a:Set = ["A","B"]
var b:Set = ["A","B"]
if a == b {
print("相等")
}else{
print("不等")
}
//过滤
var set_list:Set = ["A","B","C","D"]
let news = set_list.filter { (item) -> Bool in
if item == "B" || item == "C" {
return false
}else{
return true
}
}
//print(news)
for item in set_list {
print(item)
}
网友评论