Search code examples
iosobjective-cnsdictionarytouchesbegannsset

Access all values inside an NSSet


I was doing further study the method 'touchesBegan' of UIView and saw that this method is bringing with him two parameters which is '(NSSet *) touches' and '(UIEvent *) event'.

Regarding the parameter '(NSSet *) touches', I decided to show what it stores on the console and saw that it shows the following values:

<UITouch: 0x7ae71890> phase: Began tap count: 1 window: <UIWindow: 0x7ae71ca0; frame = (0 0; 320 480); gestureRecognizers = <NSArray: 0x7ae72820>; layer = <UIWindowLayer: 0x7ae71e90>> view: <UIView: 0x7cb89bd0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x7cb70680>> location in window: {82.5, 263} previous location in window: {82.5, 263} location in view: {82.5, 263} previous location in view: {82.5, 263}
)}

He show 'frame', 'window', 'previous location in view', 'tap count'... now how can I access all of this values separately or perhaps puts it within a NSDictionary?


Solution

  • You already have an NSSet of UITouch objects, and you have logged the properties on a UITouch object. So wether there is one UITouch object in the set or many you might fast enumerate through them with something like this:

    for (UITouch *touchObject in touches){
    
    
    UIWindow *theWindow = touchObject.window;
    NSArray *recognizers = touchObject.gestureRecognizers;
    // etc...
    
    }
    

    So there you go, you can easily reorganise this data if you wish, but it is difficult for me to see why you might wish to do so, as it appears pretty well organised by UIKit just as it is. Good luck