Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

counciler

macrumors newbie
Original poster
Jan 8, 2011
25
0
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:

Code:
[[touches anyObject] locationInView:self.view]

"touches" isn't a class but it works to call "anyObject." Another example is:

Code:
[[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.
 

JustSomeDude

macrumors regular
Apr 10, 2010
104
0
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:

Code:
[[touches anyObject] locationInView:self.view]

"touches" isn't a class but it works to call "anyObject." Another example is:

Code:
[[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.

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.
 

counciler

macrumors newbie
Original poster
Jan 8, 2011
25
0
So touches and event would be instances of their respective classes.

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:

Code:
- (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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.