「Swift5」セットを定義、初期化するサンプル
環境
# swift –version
Swift version 5.5.2 (swift-5.5.2-RELEASE)
Target: x86_64-unknown-linux-gnu
書式
let セット名 = Set(arrayLiteral: 要素1, 要素2)
print(セット名)
使用例
let citySet = Set(arrayLiteral: “東京", “大阪")
print(citySet)
let cmpSet = Set([“Yahoo", “Facebook","Twitter"])
print(cmpSet)
実行結果
[“東京", “大阪"]
[“Twitter", “Yahoo", “Facebook"]