Search code examples
objective-cclassobjecttouchesbegan

How to select object by touch.view and isKindOfClass?


i've got simple if case in touchesBegan method:

if ([touch.view isKindOfClass:[Direction class]])
{
    //select tapped object and do something...
}

i've got on view many Direction objects, and when i tap on one i want to select it, like:

Direction *d = [touch.view].selectedObject; //something like that.

Can i do this in obj-C? or how can i do this correctly?


Solution

  • if ([touch.view isKindOfClass:[Direction class]])
    {
        //do something...
        Direction *d = (Direction*)[touch view];
    }