1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| let arr1: Array<String> = ["213", "fdsf", "sdfdsg"]
var arr2: Array<String> = ["llllfs", "dqafas", "21231"] arr2 += ["sfsdfsd"] print("arr2:\(arr2)") var arr3: Array<String> = arr2 arr3.append("hhehehe") print("arr2:\(arr2)") print("arr3:\(arr3)")
arr3.append(contentsOf: ["sfsdf", "dfsfds", "dgfdg"]) print("arr3:\(arr3)") var arr4: Array<People> = [People]() for index: UInt in 0..<4 { let p = People.init(name: "渣渣辉\(index)", sex: true, age: index * UInt(arc4random()%20)) arr4.append(p) } print("arr4:\(arr4)")
var arr5: Array = arr4
arr5.removeLast() print("arr5:\(arr5)")
var arr6: Array = Array.init(arr5.dropLast()) print("arr5:\(arr5)") print("arr6:\(arr6)") var arr7: ArraySlice = ArraySlice.init(arr4)
var arr8: Array = [1, 2, 3, 4, 5, 6] arr8.removeSubrange(1...) print("arr8:\(arr8)") var arr9: Array = [1] arr9.removeSubrange(1...) print("arr9:\(arr9)") var arr10: Array = [1, 2, 3, 4, 5, 6] arr10.removeSubrange(1...3) print("arr10:\(arr10)") var arr11: Array = [1, 2, 3, 4, 5, 6] arr11.removeSubrange(1..<3) print("arr11:\(arr11)")
public mutating func removeLast(_ n: Int) public mutating func removeFirst(_ n: Int) public mutating func remove(at index: Int) -> Array.Element public mutating func removeAll(keepingCapacity keepCapacity: Bool = default)
let tanwanlanyue = ["渣渣辉", "纯扰春", "咕天落", "森红雷"]
for item in tanwanlanyue.dropFirst() { print(item) }
for item in tanwanlanyue.dropLast() { print(item) }
for (index, element) in tanwanlanyue.enumerated() { print(index, element) }
let idx = tanwanlanyue.index(of: "咕天落") let i: Int = idx! + 1 print(i)
let index = tanwanlanyue.index { $0 == "纯扰春" } let j: Int = index! + 3 print(j) if let sidx = tanwanlanyue.index(where: { (item) -> Bool in item.hasSuffix("落") }) { print(sidx) } let didx = tanwanlanyue.index(where: { (element) -> Bool in return element.hasPrefix("渣渣") }) print(didx)
let tan2 = tanwanlanyue.map { (item) -> String in let idx = tanwanlanyue.index(of: item) return item + "\(idx!)" } print(tan2)
let tan3 = tan2.filter { (item) -> Bool in let ch = item.last! return ch > "1" } print(tan3) let names = ["Paula", "Elena", "Zoe"] var lastNameEndingInA: String?
for name in names.reversed() where name.hasSuffix("a") { lastNameEndingInA = name break } print(lastNameEndingInA) for name in names.reversed() where name.hasSuffix("a") { print(name) } let last = names.last { $0.hasSuffix("a") } print(last)
略.
略.
略.
let names = ["Paula", "Elena", "Zoe"] var lastNameEndingInA: String?
for name in names.reversed() where name.hasSuffix("a") { lastNameEndingInA = name break } print(lastNameEndingInA) for name in names.reversed() where name.hasSuffix("a") { print(name) }
|