iOS swift-开发笔记2
2017-06-02 本文已影响1人
青菜白玉堂
//*****//数组获取偶数值
let numbers = [1, 2, 3, 4, 5, 6]
let evens = numbers.filter{$0 % 2 == 0}
print(evens)
//打印结果
[2, 4, 6]
//*****//判断数组序列是否包含元素
["1","6","4"].contains("2") == false
//*****//剔除数组最后一个元素
["a","b"].dropLast() == ["a"]
//*****//剔除数组第一个元素
["a","b"].dropFirst() == ["b"]
//*****//判断数组序列是否相同
["a","b"].elementsEqual(["b","a"]) == false
//*****//获取index(indices是index的复数)
["a","b"].indices == 0..<2
//*****//将序列以分隔符串联起来成为字符串
["A", "B", "C"].joined(separator: ":") == "A:B:C"
//*****//逆序,注意返回的并非原类型序列
Array([2, 7, 0].reversed()) == [0, 7, 2]