Pokémon type
When creating a program, there are times when you will want the instances of your various types to interact, in ways that allow them to communicate with each other (as in the real world). What does that mean exactly? Let's break it down.
To say we have an instance of a type means that we have an actual thing that can perform actions and respond to methods. It also has properties or attributes (hair color, eye color, and many more).
Let's start with a simple example and build on it as we progress through the chapter. Here's an example of a Pokemon
class:
class Pokemon { let name: String init(name: String) { self.name = name } }
Tip
All related source code for this chapter can be found here: https://github.com/swift-book-projects/swift-3-programming-for-kids/tree/master/Chapter-10
We've created a class called Pokemon
. This means that we've created a brand new type that can be used anywhere throughout our iOS application (such as String
,...