Some clarification about method calls

Discussion in 'iOS Programming' started by counciler, Jan 8, 2011.

  1. counciler macrumors newbie

    Jan 8, 2011
    I'm still pretty new to this programming stuff. So I've picked me up some books and have learned quite a bit. Now, I understand in objective C, in order to call a method you use the [class method] format. But what confuses me is there are some things in iPhone/iPod/iPad development that doesn't seem to follow this. For example:

    [[touches anyObject] locationInView:self.view]
    "touches" isn't a class but it works to call "anyObject." Another example is:

    [[event allTouches] anyObject]
    Where does "event" come from? I try looking at the documentation by double clicking on the name of this "class" and all it brings up for "touches" is for "touchesBegan:withEvent:", and "event" comes up with nothing. This is seriously confusing me.
  2. JustSomeDude macrumors regular

    Apr 10, 2010
    You also use this syntax for calling a method on an object - a particular instance of a class. So touches and event would be instances of their respective classes. Look for the documentation for the class associated with these objects and you'll find the methods there. You may want to review the material here.
  3. counciler thread starter macrumors newbie

    Jan 8, 2011
    Yeah, already knew this. I was more curious why I was using these instances and had no idea where they came from, then I looked back at the code and looked at the actual method I was in and saw:

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    So I guess I just needed to take a step back for a while. My head started to get really bogged down and I got pretty frustrated. What added to my confusion is each touch method I override uses "touches" and "event" as the instance name, so I was seeing them in various methods throughout my program. But now, life makes sense again, thanks!

Share This Page