Search code examples
iphonexcodeuiviewtransformcgaffinetransform

Multiple Methods named '-setTransform:' found


-(void)rotateView:(id)sender {
CGAffineTransform rotateTransform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI);
[sender setTransform:rotateTransform];//the error is shown here
}

I am getting this caution error that shows up and says Multiple methods named -setTransform: found. It only shows up when I have #import AVFoundation/AVFoundation.h in my header file. Any suggestions? Thanks


Solution

  • Cast sender to the proper class type and the warning should go away:

    [(YourClassHere *)sender setTransform:rotateTransform];
    

    As sender is passed to rotateView: as type id Xcode cannot know what actual class type it is and by that which method to call.

    Edit: Coincidentally just today Matt Gallagher of Cocoa With Love fame published an article about all kinds of issues caused by calling an ambiguous method on id in Objective-C.