Question about XCode


Hi everyone.
I have a questiom about an issue that I encountered with this chapter, and I resolved :

in the touchesbegan , the double tap calls the clearall method.
Now as I typing m y code in XCode I wrote the touhcesbegan event, and after that ( or rather beneath it in the document ) I wrote the clearall method. Now when building I would get a couple of warnings about clearall. and when running the minute I start touching the screen the app throws a fatal exception. So after looking it over I tried multiple things, until I moved the clearall method to before the touhcesbegan event. And thats when things worked fine!!
Now I would imagine when building or running the compiler loads into memory all of those methods and events, and the sequence of declaration is irrelevant. But apparently its not! Why is that?