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 - 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
-
-
First steps8m 56s
-
(Locked)
Constant and calculations7m 57s
-
(Locked)
Functions, methods, and modifiers7m 14s
-
(Locked)
HStack, VStack, and layout9m 41s
-
(Locked)
Create new files and views4m 50s
-
(Locked)
Add images10m 10s
-
(Locked)
Learn about Swift types9m 32s
-
(Locked)
Variables and scope10m 33s
-
(Locked)
Using if{}else{}8m 24s
-
(Locked)
More if{}else{}12m 46s
-
(Locked)
Create custom functions7m 58s
-
(Locked)
Structs and classes10m 55s
-
Models and views10m 37s
-
-
-