title: iOS - Why is it ok that not declare IBAction methods in the header file?
body: <p>When I was learning <a href="https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/SecondTutorial.html#//apple_ref/doc/uid/TP40011343-CH8-SW7" rel="nofollow noreferrer">Start Developing iOS Apps Today</a>, I noticed this method <code>unwindToList:</code> which has the return type of <code>IBAction</code> do not need to be declared in the header file first to pass the compilation or to run correctly. Since I can use any name I would like to as the method name, I think this is nothing to do with protocol.</p>
  
  <p>Here is the example code:</p>
  
  <p><strong>XYZToDoListViewController.h</strong>:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface XYZToDoListViewController : UITableViewController
  
  @end
  </code></pre>
  
  <p><strong>XYZToDoListViewController.m</strong>:</p>
  
  <pre><code>@implementation XYZToDoListViewController
  
  - (IBAction)unwindToList:(UIStoryboardSegue *)segue
  {
  
  }
  
  // other implementations..
  
  @end
  </code></pre>
  
  <p>After this, in the Interface Builder, as shown in the image below, I can control-drag a control to the exit icon to register this method as the action of the control. To my surprise, no error occurred after I clicked the Run button.</p>
  
  <p>I'm new to Obj-C, this was kind of blowed my mind. I know a little about C. In C I must acknowledge compiler every function by declaring it or defining it before using it.</p>
  
  <p>So I created a small project to see if I can define a method without declaration first in Obj-C.  Here is the code I tested:</p>
  
  <pre><code>// XYZFoo.h
  #import &lt;Foundation/Foundation.h&gt;
  
  @interface XYZFoo : NSObject
  
  @end
  </code></pre>
  
  <p>The .m file:</p>
  
  <pre><code>// XYZFoo.m
  #import "XYZFoo.h"
  
  @implementation XYZFoo
  - (void)bar {
      NSLog(@"hello, world");
  }
  @end
  </code></pre>
  
  <p>The main.m file:</p>
  
  <pre><code>// main.m
  #import &lt;Foundation/Foundation.h&gt;
  #import "XYZFoo.h"
  
  int main(int argc, const char * argv[])
  {
  
      @autoreleasepool {
  
          XYZFoo *foo = [[XYZFoo alloc] init];
          [foo bar];
  
      }
      return 0;
  }
  </code></pre>
  
  <p>This time I got an error. I can only fix it by adding the declaration in the header file. So in this case the declaration is required (of course).</p>
  
  <p>There must be something I'm not familiar with happened behind the scene. Can anyone explain the mechanism behind this?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT</strong>: rewrite the question to get reps to obtain the magic voting power so that I can up vote or down vote other people's answer.</p>
  
  <p><img src="https://i.stack.imgur.com/L9NNp.png" alt="drag to exit icon"></p>