By Jesse Feiler

Swift’s handling of types is similar to other languages, but each language has different emphases and rules. In general, these rules have to do with the ways typing must be implemented in cases where there is ambiguity. How much does the language (or its compiler or runtime library) do to ensure type compatibility? Swift’s approach to these issues, as you’ll see, is different from other languages.

Broadly speaking, Swift has two categories of types. In the first category, four types are built into the Swift standard library, and these are available to you without further ado.

In the second category are the types you can create. These fall into three groups:

  • structures (struct)

  • enumerations (enum)

  • classes

Structures and enumerations are basic C types, whereas classes are at the heart of object-oriented programming. All of these let you group data together into an element that can be assigned to variables (or constants) and passed around with a simple assignment statement.

If you’re not used to using structures, enumerations, and even classes, it’s worthwhile to take the time to learn about them. Although it may take a little while for you to get used to using these complex types, it’s worth it. The point is, by using a complex data structure, you can reduce the amount of code you have to write because much of the complexity is in the data structure rather than in your code.