Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Before we learn anything new about initialization, let's recap what we know so far.
-
0:04
Over the course of several different videos, we learned about initialization.
-
0:09
And while we touched on the basics of it, we didn't learn every single nuance.
-
0:13
This allowed us to keep it simple and use value and reference types in our code
-
0:18
without getting too complicated but the time has come to augment that knowledge
-
0:22
before we do that though let's quickly recap what we know about initialization.
-
0:27
Initialization as we know is the process of preparing an instance
-
0:31
of a class structure or enumeration for use by setting up
-
0:36
initial values to own stored properties and performing any other set up.
-
0:41
Initialization is carried out in a special method an init method which like a regular
-
0:46
method can take parameters for us to assign values to our story properties.
-
0:51
These parameters follow all the standard rules as regular function parameters
-
0:56
which includes local and external parameter names.
-
0:59
What else do we know?
-
1:00
We know that we can assign default values to store properties or
-
1:03
mark them optional if there are variables
-
1:06
which allows us to defer setting any values inside an in method.
-
1:10
Aside from those two cases by the time we're done with initialization
-
1:14
all stored properties must have initial values.
-
1:17
Finally, we also know that struct get a default initializer
-
1:22
known as a member-wise initializer and
-
1:25
with the wrong values also get a default initializer that accepts a raw value.
-
1:29
Okay, so far so good right?
-
1:31
In the next video look at a minor variation on an init method.
-
1:35
We've encountered these before we never stop to fully talk about them.
You need to sign up for Treehouse in order to download course files.
Sign up