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,000 courses taught by industry experts.
Solution: Create methods for the equal button
From the course: Programming for Non-programmers: iOS 17 and Swift 5
Solution: Create methods for the equal button
- [Narrator] Here's a solution to this chapter's challenge. I'm just going to copy and paste the clearWasPressed method, just like that, I'll change clear to equal, both in the name of the method and in the print statement. And then I'm just going to copy and paste the action clear was pressed, and the comma on the line above the calculator button constructor, and I'll paste it into the calculator button constructor for the equals button just like that, just before the close parenthesis there. And then I'm going to change the method name to equalWasPressed, and that should be it. So I can show the debug area to view the print statement. And there it is, and the other buttons continue to work, and that solves this chapter's challenge.
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)
-
-
-