7. Creating Your Own Syntax: Subscripts and Advanced Operators

Swift is such a powerful language that it allows you to create your own new full-fledged language. You will hear people talk about writing functional Swift and writing jQuery-like Swift. It is great to have such flexibility. With Swift you can take an existing syntax and apply it to other things. For example, subscripts allow you to provide functionality to the square-brackets notation. What you do with that square-brackets notation is up to you. You can provide subscripts for enumerations, structures, and classes. You can use subscripts to query a class to get some sort of information back.

You probably know subscripts from arrays and dictionaries. You use subscripts to access members ...

Get Learning Swift 2 Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.