/**
数组的批量操作
*/
var array1 = [1,2,3,4,5];
print("----------->")
print(array1)
// 将前两个元素替换成 9,9
array1[0...1] = [9,9]
print("----------->")
print(array1)
array1[0...1] = [9,9,11]
// 将前两个元素替换成 "0"
array1[0...1] = [00]
print("----------->")
print(array1)
/**
it will be removed in Swift 3. Use the '..<' operator.
*/
let range:CountableRange<Int> = (1 ..< 2)
array1.replaceSubrange(range,with: [9,90])
print("----------->")
print(array1)
let range1 = 1...3
array1.replaceSubrange(range1,27)"> print("----------->")
print(array1)
/**
后面添加元素
*/
// array1.append(8)
// 后面加上这个数组
// array1 += [7,7]
print("----------->")
print(array1)
array1 += array1[1...3]
print("----------->")
print(array1)
原文链接:https://www.f2er.com/swift/322490.html