O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Structures

A struct is a type that groups a set of related chunks of data together in memory. You use structs when you would like to group data together under a common type. For example, you will create a struct called Town in MonsterTown to model a town with a monster problem.

Making Town a struct encapsulates its data within a single type, and placing its definition in its own file provides a convenient location to find its implementation. In previous chapters, you modeled a town in a playground. Because the example was relatively small, this was not all that limiting. A playground is great for rapidly prototyping some code, but it does not really match the sort of projects that you will be working with in real app development. It ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required