Objective-C: Get the UITouch for which the UIEvent was triggered
ios, multi-touch, objective-c, uitouch, uiview
Solution
You can't get the touch, because sometimes multiple touches triggered the message. If the user has two fingers on the screen, and moves both, you can get a single `touchesMoved:withEvent:` in which both touches are updated.
You need to process every touch in the `touches` set. If you've disabled multitouch for the view, so that you know there will only ever be one touch in the set, you can use `touches.anyObject` to get the touch. But if you haven't disabled multitouch, you need to loop over all of the touches in the set.
The message includes a set of touches separate from `event.allTouches` because the user might have three fingers down but only move one or two of them. The `touches` set only contains the moved touches, but `event.allTouches` contains all of the user's touches, including the touches that have not moved since the last message.
The unique identifier for the touch is the `UITouch` object itself. When the user puts a finger on the screen, iOS creates a `UITouch` object. It updates that object as the user moves his finger. So you can use the `UITouch` object as the key in an `NSDictionary`, or you can attach your own objects to it using `objc_setAssociatedObject`.
Problem
I can't find anywhere in the documentation. When this message is called on my subclass of UIView: ``` - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event ``` How can I get the touch for which this message was called ? On both the NSSet and UIEvent I can get only sets of touches, but no unique identifier so I can determine which touch triggered the message. PS: why on hell would they send a NSSet of all touches, and also the possibility to get the same set from `[[event allTouches] anyObject]`