From the course: Practical Design Patterns in Swift
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Spaceships - Swift Tutorial
From the course: Practical Design Patterns in Swift
Spaceships
- [Man] Here's a naive implementation of a simplified SpaceShip class. You can follow along with me by opening the playground project from the exercise files folder, chapter eight, eight two, begin. Each SpaceShip has a mesh of polygons that describe it's geometry. It also has a texture that makes it look realistic and a position provided as coordinates in the 3D space. Note that normally, we'd use syncing to create 3D entities. I am only using this example to illustrate the problems solved by the private pattern. The following snippet creates one thousand starships. The mesh and the texture can be quite large for a detailed model. Creating a fleet might cause all sorts of problems including memory issues and low performance. If the mesh data is 100 kilobytes in size and the texture is, say, 200 kilobytes, creating one thousand spaceship instances would require more than 300 megabytes of memory. We can do better than that. Let's apply the private pattern. First, we need to identify…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.