From the course: Programming for Non-Programmers: iOS 15 and Swift 5

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Using a method as a variable

Using a method as a variable

- [Instructor] Our next step is to take our code one step further. And what we're going to do is try to meet a goal. So we can now respond when a button is pressed, but the response is limited to within the button. The issue with that is that when we press a button, we need to modify that text label in the ContentView. So if we look at our screen here, we want to be able to press a one right here and affect this object. So how do we get the data from one to the other? One way to do that is to define the method that is called when the button is pressed inside of the ContentView. And that way, we have that data within the ContentView, and we can update the text object accordingly. To accomplish that, we need to do some different things or rather some refactoring or moving around with our code. So the first thing I'm going to do is delete this call to didPressButton inside of button on line 16. And then I'm going to select…

Contents