From the course: Learning Higher-Order Functions with Swift
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Type aliases for types
From the course: Learning Higher-Order Functions with Swift
Type aliases for types
- [Instructor] So as we've been talking about types for closures and functions, sometimes they can get a little verbose, right? So we've had some pretty simple functions so far so their types have been string it, return string or int int returns int, that's fine, but when you have three, four types that are being passed in and their names are a little bit longer, or if you have a bunch of the same type like int, int, int, int, int returns string. That's not very descriptive is it? We're not really sure what each of those strings are or what's being done. This is where type aliases can come in for these types for closures and functions. They specify the type without being so verbose and you can use those in the parameter list and in the type declarations instead of the long int string int returns int. So let's look at an example. So now we have a type alias called CombinesToStrings and it defines the type string int return string. So whereas before our uses string factory function took…
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.