swift数组移除元素
extension Array {
mutating func removeValue(_ value: AnyObject) {
let arr = self.filter { (e) -> Bool in
let objc = e as AnyObject
return !objc.isEqual(value)
}
self = arr
}
}
swift数组拷贝
// 拷贝协议
protocol Copyable {
associatedtype T
func copy()-> T
}
/// 元素拷贝
extension Array where Element: Copyable {
func ele_copy() -> Array<Element> {
return self.map { $0.copy() as! Element }
}
}
/// 数组拷贝
extension Array: Copyable {
typealias T = Array
func copy() -> Array<Element> {
var arr = Array<Element>()
for ele in self {
arr.append(ele)
}
return arr
}
}
网友评论