title: Unrecognized selector sent to instance, performSelector:withObject:afterDelay: and Delegates
body: <p>using xCode 5 with ARC, Objective-C</p>
  
  <p>I have simple program, where I add additional class with protocol for new delegate (very simple).</p>
  
  <p><strong>ArrayGenerator.h</strong></p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  @protocol ArrayGeneratorDelegate &lt;NSObject&gt;
  @required
  -(void)StartTask:(NSMutableArray*)array;
  @end
  
  @interface ArrayGenerator : NSObject
  @property (nonatomic, weak) id &lt;ArrayGeneratorDelegate&gt; delegate;
  -(void)ArrayGenerator;
  @end
  </code></pre>
  
  <p><strong>ArrayGenerator.m</strong></p>
  
  <pre><code>#import "ArrayGenerator.h"
  @implementation ArrayGenerator
  
  -(void) ArrayGenerator{
  //create selector for method in Protocol
  SEL mySelector = @selector(StartTask:); 
  if (self.delegate &amp;&amp; [self.delegate respondsToSelector:@selector(StartTask:) ] ){   
      //call to method    
      [self performSelector:mySelector withObject:array afterDelay:1];
  }
  @end
  </code></pre>
  
  <p>and </p>
  
  <p>in <strong>ViewController.h</strong> I add</p>
  
  <pre><code>#import "ArrayGenerator.h"
  @interface ViewController : UIViewController &lt;ArrayGeneratorDelegate&gt;
  @end
  </code></pre>
  
  <p>in <strong>ViewController.m</strong> I add</p>
  
  <pre><code> ...
   - (void)viewDidLoad
  {
  [super viewDidLoad];
  ArrayGenerator *ag = [[ArrayGenerator alloc ]init];
  ag.delegate = self;
  [ag ArrayGenerator];
  }
  ...
  -(void)StartTask:(NSMutableArray*)array{
  NSLog( @"StartTask" );
  }
  </code></pre>
  
  <p>So I achieve, that after running app in 1 second in Log i could see "StartTask", but instead of this i simply got Exception like</p>
  
  <p><code>DelegatesWithDelay[2240:90b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ArrayGenerator StartTask:]: unrecognized selector sent to instance 0x8b55200'</code></p>
  
  <p><img src="https://i.stack.imgur.com/8O1b6.png" alt="enter image description here"></p>
  
  <p>Spend a lot of time to find something similar problem with described solution (here and other sites, but nothing from that not help's). </p>
  
  <p>Also find an alternative solution:
  instead of <code>[self performSelector:mySelector withObject:array afterDelay:1];</code> I call to <code>[NSTimer scheduledTimerWithTimeInterval:3.0 target:self.delegate selector:mySelector userInfo:nil repeats:NO];</code> - and all it's work fine, but I want to know why first variant with <code>performSelector:withObject:afterDelay:</code> not work??? (<strong>Question</strong>)</p>
  
  <p><img src="https://i.stack.imgur.com/cb219.png" alt="enter image description here"></p>
  
  <p>Also try to: </p>
  
  <ul>
  <li>recreate project - almost different - not help -same problem with
  this method, but with NSTimer - al works;</li>
  <li>change <a href="https://stackoverflow.com/a/3861653/2012219">@property attributs</a> from (nonatomic, weak), to
  (nonatomic, release) (as was recommended in some solution to similars
  problem - not help</li>
  <li>try <a href="https://stackoverflow.com/a/6729374/2012219">to use another variants</a> of performSelector methods - not
  helps</li>
  <li>try to <a href="https://stackoverflow.com/a/3126431/2012219">change</a> <code>mySelector</code> to <code>@selector(StartTask:)</code> - not
  helps</li>
  </ul>
  
  <p>and so on....nothing help, maybe i miss something?</p>