8

CUSTOM CLASSES AND STRUCTS

Image

Up to this point, the variables and constants you’ve been using were simple Int, Double, and String data types. You’ve also learned how to work with collections of data like arrays and dictionaries. In this chapter, you’ll learn how to create your own type of data by writing a custom class that can be anything you want!

A class is a package that contains different types of data and functions that use that data. A custom class is a new data type that you can use to create objects. In the real world, an object is something that can be seen and touched, like a backpack, a cat, or a car. In Swift, objects can either represent ...

Get Coding iPhone Apps for Kids, 1st 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.