Ok, I really don't want to beat the dead horse here, but I actually really do. We need to make sure we really get the concept of what we're doing when we're making these method calls. So if you have been following along with me, we have a .h and .m file that have a bunch of methods, most of which are empty. We are going to fill them in now and see if can make sense of some serious multi-method calling.
This post is going to be unique in that I'm going to suggest you spend more time looking at my code and try to see what is going on with it. It is going to be a bit of a numbers game and I'd like to see if you can follow along!
Please consider the following code, and be ready to tell me what the ending value of our globalDouble variable is at the end of the program execution! Here it is:
Ok, sorry about the images being a bit skewed, but hopefully it worked out ok. Were you able to follow what we were doing? Where did we start? viewDidLoad is where we began. Then where did we go? Well, we went all over the place. Were you able to come up with an answer to the ending value of our globalDouble variable? Ok, here is the answer I got: 1344.8. Is that what you got? Feel free to put the code in and run the app with some breakpoints if you want to make sure that you understand what is going on better.
I wanted to illustrate a very important concept with this exercise, and that is that when you call into a method, you won't leave the method until any/all other method calls are completed. It gets tricky when those methods make method calls that make method calls, etc. You can quickly get lost in a series of nested method calls, so it is important to understand that is the way it works.
Ok, I hope that you are becoming more familiar with the structure of calling and writing these basic methods. I am going to do one more post on handling methods with return types, and then we will move on to more awesome material.
Stay tuned for my next post!
No comments:
Post a Comment