Search code examples
ioscocoa-touchswiftuitouch

Getting the pointer from a touch event


So I have asked a similar question before but this one is a little different. Previous conversation: Is there a pointer for each touch point in ios

From this I get the entire touch event information. Which is really nice to have. But the information comes out like this for a single touch event:

<UITouch: 0x7b657920> phase: Began tap count: 1 window: <UIWindow: 0x7b65e150; 
frame = (0 0; 768 1024); gestureRecognizers = <NSArray: 0x7b65e590>; 
layer = <UIWindowLayer: 0x7b65b940>> view: <UIView: 0x7b660b90; 
frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0x7b660640>> 
location in window: {252.00002, 562.00012} previous location in window: {252.00002, 562.00012} 
location in view: {252.00002, 562.00012} previous location in view: {252.00002, 562.00012}

I need to figure out a way to just get the information at the beginning. The pointer right after the UITouch: I would prefer not to have to transfer this to a different array of these pointers but if need be I will. I know how to do that. I was just wondering if anyone knew how to get that pointer out of there without having to do all the extra processing.

Thanks.


Solution

  • I assume you have that long list of pointers and information in string format, so to obtain just the "0x7b657920" you could just do something like:

    var str = descriptionString //The info from the touch event
    let rangeOfPointer = Range(start: advance(str.startIndex, 10),
                         end: advance(str.startIndex, 20))
    let pointerStr = str.substringWithRange(rangeOfPointer)
    

    Hope it helps :)