Subscripting String Shortcuts

The use of subscripts in Swift has added a few nice features to its predecessor in Obj-C, not only for reading, but also for writing your own implementations.

If you are not familiar with subscripts, they define the logic that allows you to write shortcut accessors and setters for objects that can be understood as a collection, and are most commonly used in Arrays and Dictionaries:

var array = ["Hello", " ", "World", "!"]
array[2] //subscript returns "World"
array[2] = "Everybody" //The word "World" is now replaced with "Everybody" using a subscript

Continue reading “Subscripting String Shortcuts”