0
1
00:00:00,850 --> 00:00:03,890
Guys, welcome to yet another Swift Deep Dive.
1

2
00:00:03,890 --> 00:00:11,030
And in this Deep Dive, we're going to talk about structures. Now, structures helps us create custom data
2

3
00:00:11,030 --> 00:00:12,350
types.
3

4
00:00:12,350 --> 00:00:17,780
So whereas previously we saw that there were loads of basic data types that comes prebuilt along with
4

5
00:00:17,780 --> 00:00:26,620
Swift. For example, Strings, Ints, Floats, Doubles, Boolean, Arrays, and Dictionaries, you name it.
5

6
00:00:26,750 --> 00:00:30,830
There's a whole lot of different prebuilt data types.
6

7
00:00:30,830 --> 00:00:37,960
But what if we needed our own data type something that groups gather related properties and behaviors.
7

8
00:00:37,970 --> 00:00:41,400
For example, our quiz questions.
8

9
00:00:41,630 --> 00:00:49,610
Currently, we have a 2D Array which basically forces these two pieces of data, the answer and the question,
9

10
00:00:49,970 --> 00:00:51,990
to be associated with each other.
10

11
00:00:52,130 --> 00:00:56,580
But, actually, these are two properties of a question, right?
11

12
00:00:56,600 --> 00:01:02,590
The text of the actual question, as well as the correct answer of a question,
12

13
00:01:02,720 --> 00:01:10,860
those should really somehow be interlinked together. And in order to do that, we could use a structure.
13

14
00:01:11,460 --> 00:01:17,520
So we create a structure by using the struct keyword, and then we give it a name.
14

15
00:01:17,520 --> 00:01:24,670
Now, notice how the names of struct are a little bit different compared to methods or properties.
15

16
00:01:24,900 --> 00:01:30,770
When you're creating a struct, the name that you give it has to be capitalized even at the beginning.
16

17
00:01:30,840 --> 00:01:33,870
So that way, you can tell that it's actually a data type.
17

18
00:01:33,870 --> 00:01:39,900
Similar to how our string Int or Float data types, all start with a capital letter.
18

19
00:01:39,900 --> 00:01:46,500
Let's go ahead and create our own structure in playgrounds. So let's say that I was to create the structure
19

20
00:01:46,560 --> 00:01:47,700
of a town.
20

21
00:01:48,120 --> 00:01:54,510
Well, I would start by writing the struct keyword, and then I would give my structure a name.
21

22
00:01:54,540 --> 00:02:01,710
So let's just call it Town. And then I'm going to open a set of curly braces inside of which I can define
22

23
00:02:01,740 --> 00:02:03,720
the properties of my town.
23

24
00:02:03,780 --> 00:02:06,660
So what other kind of properties a town might have?
24

25
00:02:07,170 --> 00:02:09,760
Well, it might have a name, right?
25

26
00:02:09,810 --> 00:02:18,360
So let's create a constant using the "let" keyword and give this constant a name of names, so the name of the
26

27
00:02:18,360 --> 00:02:24,960
town. And then I'm going to give it a value, so let's call it "Angelaland."
27

28
00:02:24,960 --> 00:02:29,310
Now, let's think. What are some other properties that a town might have?
28

29
00:02:29,310 --> 00:02:35,500
Well, it probably has some citizens, right? But in this case, I'm going to create a variable and the variable is
29

30
00:02:35,520 --> 00:02:39,780
gonna be called citizens and it's going to be equal to an array.
30

31
00:02:39,780 --> 00:02:49,530
So these are all the people that live in Angelaland, and it will be myself and, let's say, Jack Bauer,
31

32
00:02:50,880 --> 00:02:53,750
my ultimate hero.
32

33
00:02:54,000 --> 00:03:00,120
And so now that we've got the citizens who live in the town, the name of the town, the last property I'll
33

34
00:03:00,120 --> 00:03:03,510
add are the resources in this town.
34

35
00:03:03,570 --> 00:03:14,280
So let's say that we had some "Grain," maybe 100 bags of grain, some "Ore." I think I've been playing a little
35

36
00:03:14,280 --> 00:03:17,340
bit too much of a Settlers of Catan recently.
36

37
00:03:17,430 --> 00:03:18,880
That's all I can think about.
37

38
00:03:18,930 --> 00:03:27,360
Let's say we had 42 blocks of ore. I'm not sure what's the unit of count of ore. And then, let's say we
38

39
00:03:27,360 --> 00:03:29,150
had some "Wool."
39

40
00:03:29,530 --> 00:03:32,370
Notice how here I'm creating a dictionary,
40

41
00:03:32,370 --> 00:03:39,060
So it's a variable called resources which is a collection of dictionary items.
41

42
00:03:39,060 --> 00:03:41,460
So we've got our key and our value.
42

43
00:03:41,460 --> 00:03:46,350
So a 100 bags of grain, 42 bags of ore, 75 bags of wool.
43

44
00:03:46,620 --> 00:03:56,530
And these three properties are now all packaged together into my Town structure. Now that we've created
44

45
00:03:56,530 --> 00:03:57,440
our struct,
45

46
00:03:57,490 --> 00:04:04,890
it's time to actually initialize it. By initializing, I mean creating an actual object that we can use.
46

47
00:04:06,030 --> 00:04:13,510
So to create an actual town from our town structure, all that we would need to do is create a new var
47

48
00:04:14,020 --> 00:04:17,590
and this var will be called myTown.
48

49
00:04:17,590 --> 00:04:26,410
Now, this myTown is going to be the actual town created from this structure. And to express that in code,
49

50
00:04:26,440 --> 00:04:32,620
we would write var myTown = Town, and then a set of parentheses.
50

51
00:04:32,630 --> 00:04:42,070
So now what I've done is I've created a new copy of this town structure and it's held within the variable
51

52
00:04:42,100 --> 00:04:43,360
of myTown.
52

53
00:04:44,410 --> 00:04:52,990
So that means I can actually use this object myTown and I could access the properties of myTown.
53

54
00:04:52,990 --> 00:05:01,000
For example, I could print myTown. And to access the properties, I would use the dot notation.
54

55
00:05:01,000 --> 00:05:07,130
So as soon as I write dot, you can see all the things I can tap into. And let's say that I wanted to print
55

56
00:05:07,210 --> 00:05:10,570
"Who are the people who live in my town?"
56

57
00:05:10,570 --> 00:05:18,200
I'm going to print myTown.citizens. And currently, it's just me and Jack Bauer.
57

58
00:05:18,420 --> 00:05:21,300
Now, I can tap into some of the other properties as well.
58

59
00:05:21,300 --> 00:05:29,760
So, for example, if I wanted to use my string interpolation to get hold of myTown.names or the name
59

60
00:05:29,760 --> 00:05:30,870
property of my town.
60

61
00:05:31,440 --> 00:05:37,410
And then, let's say, myTown has-- Let's do like a little report, shall we?
61

62
00:05:37,410 --> 00:05:40,110
How many bags of grain have I got?
62

63
00:05:40,350 --> 00:05:44,350
So then it would be myTown.resources.
63

64
00:05:44,400 --> 00:05:53,490
And then we would use the square brackets to access the "Grain" key, and then we could say, well, it has
64

65
00:05:53,850 --> 00:05:57,940
this many bags of grain.
65

66
00:05:58,170 --> 00:06:04,410
So now if I run my code, you can see that these are the citizens and Angelaland has 100 bags
66

67
00:06:04,410 --> 00:06:05,520
of grain.
67

68
00:06:05,550 --> 00:06:08,570
That's a pretty good, pretty good town
68

69
00:06:08,670 --> 00:06:16,080
if I might say so myself. Now, with the object that we've created, myTown, we don't have to limit ourselves
69

70
00:06:16,080 --> 00:06:24,180
to just retrieving data or retrieving the values or properties of this object. But we can also add and
70

71
00:06:24,180 --> 00:06:24,900
modify it.
71

72
00:06:25,260 --> 00:06:33,720
So for example, if let's say that my town has a new citizen, let's say that Keanu Reeves decided to
72

73
00:06:33,720 --> 00:06:35,640
move into this wonderful town.
73

74
00:06:35,790 --> 00:06:42,720
Well, then I might say myTown.citizens to access the citizen property of myTown.
74

75
00:06:42,720 --> 00:06:50,340
Well, then I can append so add something to my citizens array, and the name that I'm going to spend is,
75

76
00:06:50,340 --> 00:06:59,950
of course, our new neighbor, Keanu Reeves. So there's three of us now in our town. And I can print, for example,
76

77
00:06:59,950 --> 00:07:09,490
myTown.citizens.count. And when I do that, you can see that after I've added Keanu Reeves to
77

78
00:07:09,490 --> 00:07:16,210
the citizens of myTown, we now have three people living there. Whereas previously, when I printed 
78

79
00:07:16,220 --> 00:07:19,930
myTown.citizens, we only had two people.
79

80
00:07:19,970 --> 00:07:26,300
Now, so far, the structure of our town only defines the properties of a town.
80

81
00:07:26,330 --> 00:07:32,870
So town should have names, each town should have citizen, and they should have resources. But we can also
81

82
00:07:32,870 --> 00:07:42,050
define a behavior of our structure so we can make towns be able to do things like build barricades and
82

83
00:07:42,770 --> 00:07:51,260
get everybody inside and we sort of eat all our 100 bags of grain. And to do that, we would simply just
83

84
00:07:51,260 --> 00:07:54,020
create a function within our structure.
84

85
00:07:54,050 --> 00:08:03,890
So let's say, we created a function called fortify. And now inside this fortify function, we could simply
85

86
00:08:03,890 --> 00:08:16,840
just for ease of use, we'll just print "Defenses increased!" So now our town structure has properties and
86

87
00:08:16,960 --> 00:08:20,000
it has something that it can do.
87

88
00:08:20,000 --> 00:08:26,980
Now, when we have a function that's associated with a structure, well, then the name for it is actually
88

89
00:08:26,980 --> 00:08:28,450
called a method.
89

90
00:08:28,450 --> 00:08:35,500
So if you hear the words functions or methods, when people refer to it on StackOverflow on line, just
90

91
00:08:35,560 --> 00:08:38,350
know that they're both referring to this same thing.
91

92
00:08:38,350 --> 00:08:45,770
The thing that we create with a funky word and it defines some behavior inside the curly braces,
92

93
00:08:45,820 --> 00:08:53,620
but if this behavior was defined inside the curly braces of a structure or a class, then we would call
93

94
00:08:53,620 --> 00:08:54,570
it a method.
94

95
00:08:54,700 --> 00:09:01,330
But if it was sort of standalone, free floating around somewhere, well, then we would call it a function.
95

96
00:09:02,110 --> 00:09:02,980
At the end of the day,
96

97
00:09:03,010 --> 00:09:06,160
it's just defining behavior, something that it can do.
97

98
00:09:06,790 --> 00:09:15,550
But now I can trigger this method or this functionality that my town has by writing myTown,B
98

99
00:09:15,550 --> 00:09:20,050
so this is the actual object that can do things and has properties, dot,
99

100
00:09:20,320 --> 00:09:23,320
and I'm going to make it do something.
100

101
00:09:23,320 --> 00:09:27,850
Now, notice here that this "M" stands for method.
101

102
00:09:27,850 --> 00:09:32,780
And if I hit enter, then my town is going to fortify itself
102

103
00:09:32,950 --> 00:09:41,250
when I run that line of code. And we can see that myTown has its defenses increased, so it's able to
103

104
00:09:41,310 --> 00:09:50,260
perform an action or a behavior. When we create a struct in our code, we're essentially creating a blueprint
104

105
00:09:50,410 --> 00:09:55,660
for an eventual object that will get created from our blueprint.
105

106
00:09:55,660 --> 00:10:01,760
And in this blueprint, we get to plan ahead for how this eventual object will be.
106

107
00:10:01,870 --> 00:10:10,690
For example, we create variables, and when our variables live inside a struct, that variable is associated
107

108
00:10:10,690 --> 00:10:15,620
with our struct and it's known as a property of that struct.
108

109
00:10:16,240 --> 00:10:23,530
Similarly, we've created functions inside our struct. And when functions are created inside a struct, they're
109

110
00:10:23,530 --> 00:10:25,770
known as a method.
110

111
00:10:26,380 --> 00:10:33,730
So you can consider these properties as a way of defining what this eventual object created from the
111

112
00:10:33,730 --> 00:10:35,440
struct will be like.
112

113
00:10:35,440 --> 00:10:43,960
So its attributes or its properties and the methods can be thought of as what the objects can do.
113

114
00:10:44,830 --> 00:10:52,690
So in the context of an actual car object that gets created from a car struct or car blueprint,
114

115
00:10:52,720 --> 00:10:58,690
well, those properties might be things like the color of the car or the number of seats it has, or the
115

116
00:10:58,690 --> 00:11:05,500
number of doors it has, or whether if it's a hatchback or a sedan, something that describes what this
116

117
00:11:05,500 --> 00:11:09,880
eventual object is going to be like. And the methods for the car,
117

118
00:11:09,880 --> 00:11:13,450
well, those are things that the car object can do,
118

119
00:11:13,450 --> 00:11:22,450
so things like drive or brake, or switch on the indicator lights. And it's through describing these properties
119

120
00:11:22,450 --> 00:11:28,360
and methods of the objects that will get created when our app is running.
120

121
00:11:28,390 --> 00:11:34,570
So these objects are invisible. We can't see them. We can't touch them. But we can plan for how they will
121

122
00:11:34,570 --> 00:11:37,240
behave and how they will look
122

123
00:11:37,390 --> 00:11:44,080
by creating these properties and methods. So when we were defining our town struct, we were writing the
123

124
00:11:44,080 --> 00:11:52,090
blueprint for the eventual object that will get created. And we can take our blueprint and initialize
124

125
00:11:52,090 --> 00:11:55,790
it which turns it into the actual object.
125

126
00:11:55,810 --> 00:11:57,900
In this case, maybe an actual car.
126

127
00:11:58,480 --> 00:12:05,510
But what do I mean by that? What is initializing mean and what does the code actually look like?
127

128
00:12:05,510 --> 00:12:07,210
Just like we would create a function, 
128

129
00:12:07,250 --> 00:12:13,850
we create our initializer in a pretty similar way. We have are parentheses for the inputs that gets
129

130
00:12:13,850 --> 00:12:15,020
passed over.
130

131
00:12:15,020 --> 00:12:21,840
We have our curly braces for the implementation or the code for how to initialize our structure.
131

132
00:12:21,920 --> 00:12:24,540
So how does the initializer get used?
132

133
00:12:24,550 --> 00:12:31,940
Well, the initializer gets triggered when we create our object from our blueprint. But why do we have
133

134
00:12:31,940 --> 00:12:34,080
initializers in the first place?
134

135
00:12:34,100 --> 00:12:36,110
What's the purpose of the initializer?
135

136
00:12:36,890 --> 00:12:41,950
Well, suppose you want to create the next civilization or Settlers of Catan video game,
136

137
00:12:42,410 --> 00:12:45,190
well, in that case, you're going to need more than one town,
137

138
00:12:45,230 --> 00:12:45,980
right?
138

139
00:12:46,100 --> 00:12:54,020
Well, in addition, to Angela Land, you'll need Athens, Beijing, and New Delhi, and many, many more, but all
139

140
00:12:54,020 --> 00:12:55,560
of these places are different.
140

141
00:12:55,580 --> 00:12:59,940
They have a different name, different citizens, and different resources.
141

142
00:12:59,960 --> 00:13:05,840
Wouldn't it be nice if we could use our struct to act as a blueprint for all of these towns, but still
142

143
00:13:05,840 --> 00:13:08,060
be able to customize each town?
143

144
00:13:08,060 --> 00:13:10,730
Well that's where the initialize it comes in.
144

145
00:13:10,730 --> 00:13:16,660
Let's head back into playgrounds to see this in action. Let's delete everything we have here currently
145

146
00:13:16,670 --> 00:13:19,570
and just be left with our structure.
146

147
00:13:19,570 --> 00:13:27,040
Now, I'm also going to delete the values of these properties to keep my town very generic. So the name
147

148
00:13:27,070 --> 00:13:30,200
is going to be a string data type.
148

149
00:13:30,220 --> 00:13:37,510
The citizens are gonna be an array of strings and the resources are going to be a dictionary made up
149

150
00:13:37,570 --> 00:13:42,520
of strings for keys and integers for values.
150

151
00:13:42,550 --> 00:13:50,950
So now my town structure has blank properties for each of these attributes and I can now define a custom
151

152
00:13:50,950 --> 00:13:51,850
property
152

153
00:13:51,850 --> 00:13:53,530
every time I create a new town.
153

154
00:13:54,100 --> 00:13:57,370
But before we do that, we need to create the initializer.
154

155
00:13:57,760 --> 00:14:03,670
So I'm just gonna write "init." And when my swift code snippet symbol comes up, I'm just gonna hit enter.
155

156
00:14:04,290 --> 00:14:11,470
And inside the place holder which says "parameters," I'm going to add some input parameters, so when
156

157
00:14:11,470 --> 00:14:15,190
I initialize a new town from myTown structure,
157

158
00:14:15,190 --> 00:14:19,210
I'll be able to use these inputs to fill in my properties.
158

159
00:14:19,300 --> 00:14:25,100
The first one is going to be townName which is going to be of type String.
159

160
00:14:25,300 --> 00:14:30,470
Next, it's going to be the people of the town which are going to be an array of strings.
160

161
00:14:30,880 --> 00:14:39,130
And finally, I've got the stats for my town which is going to be a dictionary comprised of String keys
161

162
00:14:39,250 --> 00:14:41,200
and Integer values.
162

163
00:14:41,200 --> 00:14:46,350
So that's all three inputs that I need for my initializer.
163

164
00:14:47,050 --> 00:14:53,500
And inside the initializer, what I'm gonna do is I'm going to set my town's name property to equal
164

165
00:14:53,500 --> 00:15:03,270
whatever got passed in as the townName, and then I'm going to set my citizens property to equal whatever
165

166
00:15:03,270 --> 00:15:06,100
got passed in as the people of the town.
166

167
00:15:06,180 --> 00:15:13,830
And finally, my resources property is going to be populated with these stats that have been inputed for
167

168
00:15:13,830 --> 00:15:15,600
this town.
168

169
00:15:15,600 --> 00:15:22,620
So now if we're creating our town with an initializer, the  way that we would do that is, let's create
169

170
00:15:22,620 --> 00:15:24,140
a variable code,
170

171
00:15:24,210 --> 00:15:33,630
I don't know, another town, and let's set it to equal a town created with our Town blueprint.
171

172
00:15:33,630 --> 00:15:40,890
And then, once we open a set of parentheses, you can see all of those input parameters show up, townName,
172

173
00:15:40,890 --> 00:15:42,420
people, and stats.
173

174
00:15:42,450 --> 00:15:49,830
So if we hit enter, we can use these placeholders and you can hit tab to go between them, and we need
174

175
00:15:49,830 --> 00:15:56,680
to provide some values in each of these positions. And we can also see what type of data we need to provide.
175

176
00:15:56,700 --> 00:15:59,940
So the first one for the town name has to be a String.
176

177
00:16:00,120 --> 00:16:10,710
So let's call this "Nameless Island." And the people who live in this Nameless Island will just be one
177

178
00:16:10,710 --> 00:16:13,290
guy and it's gonna be Tom Hanks.
178

179
00:16:13,290 --> 00:16:21,780
And for the stats of this town that I'm creating, it's just gonna have a whole lot of coconuts.
179

180
00:16:21,780 --> 00:16:26,580
And let's say, it's got 100 coconuts on this Nameless Island.
180

181
00:16:26,760 --> 00:16:34,740
So now that I've created another town, I can do exactly as what I've done before, I can tap into my object,
181

182
00:16:34,920 --> 00:16:40,750
the anotherTown. So remember the object is the thing that's actually created from the blueprint.
182

183
00:16:41,310 --> 00:16:50,310
And I can, of course, print the properties, say, the citizens or the name, I can call or trigger the methods
183

184
00:16:50,310 --> 00:16:57,270
or the behaviors that the town can do, namely fortify itself, but I can also, of course, tap into, let's
184

185
00:16:57,270 --> 00:17:05,220
say, our citizens. And then just as we did before, we can append a new element which happens, in this case,
185

186
00:17:05,220 --> 00:17:11,370
to be a beach ball who's going to join the citizens of Nameless Island, and he's gonna be called Wilson.
186

187
00:17:12,180 --> 00:17:19,440
So now we have another town which is an object created from the Town blueprint with all of these properties
187

188
00:17:19,440 --> 00:17:23,910
that we've specified when we created the town using the blueprint.
188

189
00:17:24,180 --> 00:17:30,840
And we're able to use this object just as we did before to tap into its properties or to manipulate
189

190
00:17:30,870 --> 00:17:32,750
or change some of those properties.
190

191
00:17:32,970 --> 00:17:40,000
And we can, again, if we wanted to, now print our anotherTown, so our objects property.
191

192
00:17:40,200 --> 00:17:42,870
Let's print and see who lives in this town.
192

193
00:17:43,950 --> 00:17:50,570
So this time it prints, there's "Tom Hanks" and there's "Wilson" on Nameless Island.
193

194
00:17:50,570 --> 00:17:57,690
Now, notice how I'm twisting these names so that they don't overlap with the names I've got as the properties
194

195
00:17:57,690 --> 00:18:03,920
of my town. Because in reality, it would be much easier for me to just name this name,
195

196
00:18:03,930 --> 00:18:08,910
name these citizens, and name these resources.
196

197
00:18:08,910 --> 00:18:18,420
But now, when I initialize it, I have to set the name equal to name, and the citizens equal to the
197

198
00:18:18,420 --> 00:18:22,740
citizens, and the resources equal to the resources.
198

199
00:18:22,740 --> 00:18:26,220
Now, it kind of makes sense if you really think about it.
199

200
00:18:26,250 --> 00:18:34,950
So I'm saying that the name property of myTown structure should be set to equal the name that got passed
200

201
00:18:34,950 --> 00:18:37,710
in as the input parameter.
201

202
00:18:38,250 --> 00:18:45,180
But this code is very confusing because this name matches exactly this name.
202

203
00:18:45,180 --> 00:18:46,830
Now what else can I do?
203

204
00:18:47,820 --> 00:18:55,080
Well, I can make it really explicit which one I'm talking about whether if it's the property or whether
204

205
00:18:55,080 --> 00:19:02,790
if it's the input here by simply adding the word "self" in front. Now, you might have already come across
205

206
00:19:02,790 --> 00:19:09,660
this keyword "self" and we haven't really gotten round to explaining it and this is the perfect time
206

207
00:19:09,660 --> 00:19:19,080
to really explain it. Because the "self" keyword refers to the eventual object that will be created from
207

208
00:19:19,230 --> 00:19:22,020
this structure blueprint.
208

209
00:19:22,020 --> 00:19:30,180
Whereas right now, we're saying self.name referring to the property name of our structure town. 
209

210
00:19:30,270 --> 00:19:37,830
Well, eventually, when we try to initialize our town, that "self" is going to refer to the object that's initialized,
210

211
00:19:37,830 --> 00:19:46,590
so, for example, the anotherTown. By adding that "self" keyword in front of all of these properties, I can
211

212
00:19:46,590 --> 00:19:54,060
now easily differentiate them by saying, well, self.name, of course, refers to my town's name property,
212

213
00:19:54,620 --> 00:19:55,910
self.citizens,
213

214
00:19:55,920 --> 00:19:59,100
of course, refers to my town's citizens.
214

215
00:19:59,320 --> 00:20:04,210
And you can view this "self" keyword as referring to the structure.
215

216
00:20:04,210 --> 00:20:12,880
Now, that I've changed the parameter names of my initializer for my town structure, well, I also have to
216

217
00:20:12,880 --> 00:20:14,480
change them here,
217

218
00:20:14,500 --> 00:20:15,370
right?
218

219
00:20:15,370 --> 00:20:17,620
So this is what this error is about.
219

220
00:20:17,620 --> 00:20:25,960
It says that the labels should be the name citizen resources, but instead, we have townName, people, and
220

221
00:20:25,960 --> 00:20:33,070
stats. So we can go ahead and click Fix for it to change it for us to the ones that we specified in the
221

222
00:20:33,070 --> 00:20:35,760
initializer the and all the errors go away.
222

223
00:20:36,550 --> 00:20:45,370
But from now on, also, when we create, say, let's create a ghostTown from our Town blueprint,
223

224
00:20:45,370 --> 00:20:49,260
and when I hit enter, you'll see that these are now the parameter names
224

225
00:20:49,270 --> 00:20:56,300
I have to provide. Let's create all ghostTown which is going to be called
225

226
00:20:56,650 --> 00:21:01,810
"Ghosty McGhostface," and the citizens are none.
226

227
00:21:01,810 --> 00:21:04,590
There's nobody living here because it's a ghost town.
227

228
00:21:05,020 --> 00:21:16,160
And the resources are--just got like a lot of "Tumbleweed" of 1, just tumbling around in our ghost town.
228

229
00:21:16,160 --> 00:21:24,090
So notice how right now I've got one object created from my Town blueprint which is called anotherTown.
229

230
00:21:24,320 --> 00:21:31,610
And in there, we've got Tom Hanks with a bunch of coconuts, and we've got another town called ghostTown
230

231
00:21:31,730 --> 00:21:35,510
which, again, we've created from exactly the same blueprint.
231

232
00:21:35,660 --> 00:21:37,320
But this town is completely different,
232

233
00:21:37,340 --> 00:21:38,840
it's got a different name,
233

234
00:21:38,840 --> 00:21:45,520
it's got no citizens, and it's got just a single tumbleweed, "Tumbleweed."
234

235
00:21:45,530 --> 00:21:51,740
So now when we tap into our objects, let's say that in another town, we've got a new citizen who's moved
235

236
00:21:51,740 --> 00:21:54,950
in, so we'll append "Wilson" to that town.
236

237
00:21:55,580 --> 00:21:59,630
Whereas in the ghostTown, well, nothing really happens.
237

238
00:21:59,630 --> 00:22:04,640
But let's say that we just decided to fortify the town.
238

239
00:22:04,640 --> 00:22:11,810
Notice how here I'm tapping into different objects that have essentially been created from the same
239

240
00:22:11,810 --> 00:22:12,790
blueprint.
240

241
00:22:12,830 --> 00:22:19,040
And when I hold down option, click on each of these objects, you can see that they both have the same
241

242
00:22:19,130 --> 00:22:19,860
data type.
242

243
00:22:19,880 --> 00:22:26,130
They're both created from the town structure. But they are really different from each other.
243

244
00:22:26,150 --> 00:22:29,400
They have different names, different citizens, different resources,
244

245
00:22:29,630 --> 00:22:35,750
and I can specify which one I want to manipulate, which one I want to change, whose properties I want
245

246
00:22:35,750 --> 00:22:37,410
to tap into.
246

247
00:22:37,730 --> 00:22:45,380
And now, we've got essentially a whole bunch of things that we can play with by using this blueprint
247

248
00:22:45,530 --> 00:22:47,220
as a starting point.
248

249
00:22:47,240 --> 00:22:53,990
So now that you've learned all about structures, it's time to test your knowledge in the structures assignment.
249

250
00:22:54,320 --> 00:22:55,410
So head over there before you continue in the project.
250

251
00:22:55,700 --> 00:22:59,090
So head over there before you continue in the project.
251

252
00:22:59,330 --> 00:23:02,060
And once you're back, I'll see you on the next lesson.
