ios - Swift 3 从数组中删除不存在于另一个数组中的对象并保持顺序

标签 ios arrays swift3

Array1 = [华盛顿、富兰克林、佛罗里达、阿拉斯加、加利福尼亚、佐治亚]

Array2 = [加利福尼亚、华盛顿、佐治亚]

我想得到

Array1 = [华盛顿、加利福尼亚、佐治亚]

最佳答案

var array1 = ["Washington", "Franklin", "Florida", "Alaska", "California", "Georgia"]
var array2 = ["California", "Washington", "Georgia"]

let filterArray = array1.filter {
    array2.contains($0)
}

filterArray 就是你想要的

关于ios - Swift 3 从数组中删除不存在于另一个数组中的对象并保持顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45500973/

相关文章:

ios - pod 安装 swift 2.3 框架而不是 swift 3 代码

ios - UITableView : Action only works every second time 问题

ios - 如果我在 iOS8 模拟器上运行应用程序,来自 xib 的 IBOutlet 不会初始化

ios - UIView bringSubviewToFront : does *not* bring view to front

ios - 推断错误: External Error: *** capture failed to execute: exited with code 65

python - 将函数应用于 3d numpy 数组切片的最佳方法

java - 在 Java 中,如何获取二维数组的值并将它们存储在另一个具有不同列和行大小的二维数组中?

Jquery数组appendTo通过函数

ios - swift 3.1 : Cannot convert value of type '(_) -> ()' error/Problems with closures

ios - iOS10上的CoreBluetooth:CBPeripheral discoverServices之后超时