How to resolve "no known instance method for selector 'performSelector:withObject:afterDelay:'" when migrating to ARC?

openfrog picture openfrog · Jan 13, 2012 · Viewed 12.2k times · Source

The ARC migration tool is refusing to accept this code prior to starting with migration:

[self.delegate performSelector:@selector(overlayDismissed:) withObject:self afterDelay:0];

The delegate is forced to implement this method with a protocol, and it should work fine:

@protocol OverlayDelegate <NSObject>
- (void)overlayDismissed:(Overlay*)overlay;
@end

@interface Overlay : UIImageView {
    id<OverlayDelegate> delegate;
}

@property (nonatomic, assign) id<OverlayDelegate> delegate;

What's wrong with ARC? Why is it telling me that there is "no known instance method for selector 'performSelector:withObject:afterDelay:'?

Answer

dtuckernet picture dtuckernet · Jan 13, 2012

ARC isn't causing this - it is is merely exposing it. That method is defined on NSObject - but id works for more than just NSObject (so you have to be more specific than just 'id'). Change your code to this:

@interface Overlay : UIImageView {
    NSObject<OverlayDelegate> *delegate;
}

@property (nonatomic, assign) NSObject<OverlayDelegate> *delegate;