title: How to use @objc protocol with optional and extensions at the same time?
body: <p>This code does not compile and might sound stupid as it is, but i'll explain why it's so important!</p>
  
  <pre><code>@objc protocol p {
      optional func f1()
      func f2()
  }
  
  extension p {
      func f1() { }
      func f2() { }
  }
  
  
  class foo: p {
  }
  </code></pre>
  
  <p>Compiler says <code>Type c does not conform to protocol 'p'</code> and that's maybe because you can not use @objc optional and extensions at the same time (and does not make sence in this scenario either). But consider the following example:</p>
  
  <p>I want to set a selector on a non-optional method defined in protocol in my extension (main reason i used @objc):</p>
  
  <p><code>func f1() { }</code> -> <code>func f1() { ... #selector(Self.f2) ... }</code></p>
  
  <p>And i also want my <code>f2()</code> function to have default behaviour. If i mark <code>f2()</code> as <code>optional</code>, it can not be used in <code>#selector</code> because compiler does not know if this method actually exists in the case of need. Sure there're lots of nasty workarounds like global methods, sending <code>Selector</code>s to methods as input and etc, but is there a clean way to achieve it?</p>
  
  <hr>
  
  <p><strong>This is the practical issue</strong></p>
  
  <pre><code>@objc
  protocol Refreshable {
      weak var refreshControl: UIRefreshControl? { get set }
      optional func setupRefreshControl()
      func refresh()
  }
  
  @objc
  protocol ContentLoader {
      func load(reset: Bool)
  }
  
  extension Refreshable where Self: ContentLoader {
      func refresh() {
          delay(0.75) { [weak self] in
              self?.load(true)
          }
      }
  }
  
  extension Refreshable where Self: UICollectionViewController {
      func setupRefreshControl() {
          let newRefreshControl = UIRefreshControl()
  
          newRefreshControl.tintColor = UIColor.grayColor()
          newRefreshControl.addTarget(self, action: #selector(Self.refresh), forControlEvents: .ValueChanged)
          collectionView?.addSubview(newRefreshControl)
          refreshControl = newRefreshControl
      }
  }
  </code></pre>
  
  <p>Now if a ViewController implements <code>Refreshable</code> and <code>ContentLoader</code>, it does not find the default <code>refresh</code> function, but it does find <code>setupRefreshControl</code>. So i figured let's mark <code>refresh</code> as optional too, but by doing that, you can not send it to selector any more.</p>
  
  <p>I even tried this:</p>
  
  <p><code>func refresh()</code> -> <code>optional func refresh()</code>
  and</p>
  
  <pre><code>let str = "refresh"
  let sel = Selector(str)
  </code></pre>
  
  <p>It silents the compiler yes, but does not work either... rises <code>unrecognized selector sent to instance....</code></p>