Programming in Swift: Fundamentals

Oct 19 2021 · Swift 5.5, iOS 15, Xcode 13

Part 5: Functions & Named Types

34. Introduction

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 33. Conclusion Next episode: 35. Introduction to Functions

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 34. Introduction

Update Notes: The student materials have been reviewed and are updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Hey everyone. I'm Chris. And welcome to the final part of this course: functions and named types. Now, so far in this course, you've used the type that Swift gives you straight out of the box. But in this part of the course, you'll be combining a lot of what you've learned to create your own types. Now, before we get started, we need to go over some terminology first. So you've heard the term 'type' use to describe things like ints and strings, but there are actually two kinds of types, name types, and compound types. Now a name type is a type that has a name when it's defined, and you learn about two named types in this part, structures and classes. Now, most of the types, you already know are also named types. Ints, strings, booleans, even arrays. They're all named types. So named types have names, but compound types don't have names. Instead compound types are defined by the other types they contain. They can be made up of named types or even other compound types. Now, instead of a name, a compound type is expressed by what's known as a type signature. And to show me an example, take a look at these tuples. Tuples are a compound type. Tuples can be made of two ints or a string and a boolean or a double and a tuple of two ints. Now you'll learn about one more compound type in this part, functions. We wrote some of these in Bullseye, but you called them methods and I'll talk a bit about why that is. Now, types can be ascribed in another important way by how the data is stored and how it's copied. All the types we've been working with in this course are value types. So when you assign the value of one instance of a value type to another instance of that type, those two instances are completely independent. So strings, they're value types. If you make a copy of this name and set the value of the copy to something completely different, those two names will no longer match. Now, structures and tuples are value types. Now, reference types, they work differently. If you make a copy of a reference type, the two instances are both referencing the same data. Making a change to one instance also changes the other instance, classes and functions are reference types. Now I'll be covering a lot of new material in this part. You'll start out with the solid introduction to functions. So functions, a lot like the methods you saw on Bullseye provide functionality to your app, but they also help you reuse code. Then next, you're going to write a basic structure and learn about its parts, properties; which is what a structure has, and methods; that's what a structure does. And you'll finish up this part, and the course, with an introduction to classes. Classes are really similar to structures. They also have properties and methods, but one big difference is that classes copy values. So you'll revisit the whole idea of value and reference types there. And, I will still have a few challenges for you along the way to help you check your knowledge, but also get some great practice. So when you're ready, head on into the next video where you'll take a look at functions.