4. Structuring Code: Enums, Structs, and Classes

This chapter covers the basic structural methods of Swift: enums, structs, and classes. With these tools, you can more easily organize your code for reuse. You will find yourself typing less code when using these tools properly. Structs, enums, and classes are similar to functions in that they allow you to group some code together for reuse. They are different from functions because they can contain functions.

If you are familiar with Objective-C, C, C++, or Java and other languages, you should know about enums because they are a part of many languages. You write typedef because in Objective-C and C (but not C++), you have to always precede an enum with the word enum. You create a typedef to make ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.