Unlike in Swift 3, we can specify range at only one side in Swift 4 to get subset of a collection.
-------------------------------------------------------------------------------------------
let food = ["banana", "apple", "orange", "coke", "pepsi"]
let fruits = food[...2] //at right
let drinks = food[3...] //at left
print("\(fruits)") // ["banana", "apple", "orange"]
print("\(drinks)") // ["coke", "pepsi"]
-------------------------------------------------------------------------------------------
Hope this post is useful. Feel free to comment incase of any queries.
No comments:
Post a Comment