Declaring an array:
var arr = [1, 2, 3, 4, 5]
Removing subrange:
var arr = ["a", "b", "c", "d", "e"]
print("> Before: arr=\(arr)")
arr.removeSubrange(3..<arr.count)
print("> After: arr=\(arr)")
Result:
> Before: arr=["a", "b", "c", "d", "e"]
> After: arr=["a", "b", "c"]
The lower bound and upper bound of the subrange operator "..<" must be positive and not greater than the array's max index, respectively.
No comments:
Post a Comment