Embed presentation
Download to read offline

![subscript
[] = subscript operator](https://image.slidesharecdn.com/swift0x0csubscript-140801160930-phpapp01/85/Swift-0x0c-2-320.jpg)

![subscript usage
var numberOfLegs = [ “spider”:8, “ant”:6”, “cat”:4]
numberOfLegs[“bird”] = 2](https://image.slidesharecdn.com/swift0x0csubscript-140801160930-phpapp01/85/Swift-0x0c-4-320.jpg)


Subscripts in Swift allow accessing elements in a collection by their index or key. The subscript operator [] is used to define subscripts on types to allow customized access to elements similar to array indexing. Subscripts can have a getter and setter to retrieve or set values and are commonly used with dictionaries to access values by their keys.

![subscript
[] = subscript operator](https://image.slidesharecdn.com/swift0x0csubscript-140801160930-phpapp01/85/Swift-0x0c-2-320.jpg)

![subscript usage
var numberOfLegs = [ “spider”:8, “ant”:6”, “cat”:4]
numberOfLegs[“bird”] = 2](https://image.slidesharecdn.com/swift0x0csubscript-140801160930-phpapp01/85/Swift-0x0c-4-320.jpg)
