0
我有兩個數組填充字符串,希望能夠識別兩個數組中的匹配字符串。例如。查找數組中的匹配元素SWIFT 3
var ArrayOne = ["Dog", "Cat", "Chicken"]
var Array Two = ["Dog", "Elephant", "Chicken", "Sheep"]
我想要的結果是提前
我有兩個數組填充字符串,希望能夠識別兩個數組中的匹配字符串。例如。查找數組中的匹配元素SWIFT 3
var ArrayOne = ["Dog", "Cat", "Chicken"]
var Array Two = ["Dog", "Elephant", "Chicken", "Sheep"]
我想要的結果是提前
var ArrayOne = ["Dog", "Cat", "Chicken"]
var ArrayTwo = ["Dog", "Elephant", "Chicken", "Sheep"]
var ArrayThree = [String]()
for animal in ArrayOne {
if ArrayTwo.contains(animal) {
ArrayThree.append(animal)
}
}
的可能的複製https://stackoverflow.com/questions/24589181/set-operations-union
謝謝-In-swift-array –
'let matching = Set(ArrayOne).intersection(ArrayTwo)' – vacawama