If you're following along with me from the last post, we just ventured a look at the ExampleViewController.m file. Understanding the basic structure of the implementation file is critical for everything we do going on. Let's look at an image that shows us the main parts of our implementation file:
Just to make things simple, I'll go ahead and point out some relevant points about each letter:
A - This area of the implementation file is where you import files. This is how you connect the .m file to the .h file, you are actually importing it at the top telling the computer that there will be things referenced in the .m file that are actually defined or detailed in the .h file. As the complexity of our app increases, you will see the need to import other class header files as well.
B - This line points out that everything below is the implementation of the ExampleViewController class. The syntax is pretty self explanatory. You won't need to do anything with this other than know that that is what it is doing. It might be helpful to scroll all the way down to the bottom and see the @end symbol. That is telling you where the implementation part of the ExampleViewController class ends.
C - As you can see, there is more than one C that we are looking at. The reason for this is that these pieces of code are the same thing. Look those pieces of code over, can you see any similarities? You are looking at three different methods. A what? A method. Say it out loud five times. Similar to variables, methods are an essential building block of programming in Objective-C.
Aside from import and a few different declarations you may do at the top of the .m file, basically all of your .m file is going to be methods. It is important to note that for the most part, all the code that you write has to take place inside of a method.
In my next post I will discuss the importance of scope within a method.
Hey, I noticed that when I opened the exampleviewcontroller.m that the @end symbol is both at the bottom and the top after line A.
ReplyDeleteShould i modify the code so that the @end symbol is only at the end of it?
I don't know for sure what you are referring to, but I think you're referring to the class extension. If it isn't causing an error, than go ahead and leave it how Xcode has it. The template designs for projects are constantly evolving.
ReplyDelete