Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:'?

like image 570
openfrog Avatar asked Jan 13 '12 01:01

openfrog


1 Answers

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;
like image 141
dtuckernet Avatar answered Oct 22 '22 15:10

dtuckernet