From the course: Programming for Non-programmers: iOS 17 and Swift 5
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Using methods
From the course: Programming for Non-programmers: iOS 17 and Swift 5
Using methods
- [Instructor] Now let's get some practice writing methods in a playground. If you didn't see how to create a playground before, you can do it from file, new and then playground. So I've hit the run button here and there's the output of my greeting. And let's create a method. Go down a few lines, and we'll create a method with the keyword func, and then we'll call this get new greeting. So we're using camel case there, so capital N and capital G, and then some parentheses and the data type it's going to return, so hyphen, then a greater than sign, it's going to be string, so capital S on that, and then put some curly braces. In here, we're going to return some kind of a string. Remember, a string should be in a set of double quotes. Now remember, we need to call the method at some point. So we've defined the definition and now we need to execute it. I'm going to execute it by setting the value of greeting equal to get new greeting. And I'll just use the code hinting there by pressing…
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.
Contents
-
-
-
-
-
-
(Locked)
Understanding methods5m 30s
-
(Locked)
Using methods3m 47s
-
(Locked)
Running code when a button is pressed3m 43s
-
(Locked)
Using a method as a variable4m 46s
-
(Locked)
Passing parameters to method variables3m 24s
-
(Locked)
SwiftUI binding5m 21s
-
(Locked)
Using different methods to handle different events3m 2s
-
(Locked)
Challenge: Create methods for the equal button52s
-
(Locked)
Solution: Create methods for the equal button48s
-
(Locked)
-
-
-