Good day,
I'm new to Swift (and object-oriented languages altogether) and I'm creating an iPad app that lets you draw using your finger. I'm currently trying to manage multitouch events correctly, and I'd like to keep track of the touches. The idea is to draw only following one touch, and discard the others, ignoring them even after the initial touch has ended.
For that, I need to identify each touch, but the UITouch object doesn't contain an ID. Actually, since touches are stored in an NSSet, they aren't ordered.
Erring on the internet, I found a possible solution storing the adresses of the touches in a CFDictionary. This seems reasonable in Objective-C, but Swift isn't very pointer-friendly and I haven't managed to create a CFDictionary taking pointers on UITouch as value.
Does anyone know how to handle this ? Am I using CFDictionaries wrong (I tried having UnsafePointer<UITouch>
as value) ? Is there another solution that I overlooked ?
Thanks for your help.
I only wanted a simple key for the touch and used string interpolation of the UITouch to get one. The string interpolation of my touch looked like this:
All I needed was that second part, so I wrote the following method to extract it.
In this case, it returns:
I could clean it up if necessary, but as it's already repeatable over the lifetime of the touch, I didn't add anything else.