Sunday, October 8, 2017

Swift 4 NEW Tutorial-1 (One Sided Ranges)

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.