title: Swift 4 Objective-C Runtime and casting to NSObjectProtocol
body: <p>In Swift 3, I had a snipped of code that called into Objective-C runtime to check if a certain class is present.</p>
  
  <pre><code>guard let managerClass = NSClassFromString("ASIdentifierManager") as? NSObjectProtocol else {
      return nil
  }
  </code></pre>
  
  <p>This returns <code>AnyClass</code> instance and it is castable to <code>NSObjectProtocol</code> - so I could call methods like <code>responds</code> and <code>perform</code> to work with selectors.</p>
  
  <p>In Swift 4, this still works at runtime, but will emit a warning:</p>
  
  <blockquote>
    <p>Cast from 'AnyClass?' (aka 'Optional') to unrelated type 'NSObjectProtocol' always fails</p>
  </blockquote>
  
  <p>Oddly it still works, but I am worried a certain Swift version will kill the code.</p>
  
  <p><strong>What is the proper way to get rid of this warning? To what should I cast the object, to be able to perform selectors on it dynamically?</strong></p>