From the course: Make SwiftUI Playgrounds Applications

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Functions, methods, and modifiers

Functions, methods, and modifiers - Swift Tutorial

From the course: Make SwiftUI Playgrounds Applications

Functions, methods, and modifiers

- [Steven] We have identifiers for values we can use repeatedly. If you think of constants as nouns we'll need some verbs to do actions. Swift has actions we can use repeatedly. We call these functions. Here's a simple example. Add this to your code just below the thing2 declaration. So I'm going to put another let in here and then we're going to use a new identifier, we'll call it myMax. And we're going to put this in a string. So I'm going to make this string interpolation, like we've done before. And inside there I'm going to use the function max. And you can see that it shows up in our auto complete. So I'm just going to press return for that. And it's got two things that it needs to put in here. And I'm going to put in thing here and I'll hit tab and hit thing2 here. This is a function. A function is a set of code stored somewhere that does something you want done. In this case, the max function finds which…

Contents