Book Image

Mastering Swift

By : Jon Hoffman
Book Image

Mastering Swift

By: Jon Hoffman

Overview of this book

Table of Contents (22 chapters)
Mastering Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 7. Custom Subscripting

Custom Subscripts were added to Objective-C in 2012. At that time, Chris Lattner was already two years into developing Swift and like other good features of Objective-C; Subscripts became a part of the Swift language. I did not frequently use custom subscripts in Objective-C, but I did know that they were a part of the language when I needed them. Subscripts in Swift seem, to me, to be a more natural part of the language, possibly because they were part of the language when it was released and not added in after.

In this chapter, you will learn the following topics:

  • What are custom subscripts?

  • How to add custom subscripts to classes, structures, or enums?

  • How to create read/write and read-only subscripts?

  • How to use external names with out custom subscripts?

  • How to use multidimensional subscripts?