2

I am having an issue checking for objective-c protocol conformance when it is inherited from a swift protocol. As far as I understand the following code should print true. (Swift 3)

import UIKit

protocol MyProtocol: UITableViewDelegate {}

class MyClass: UIViewController, MyProtocol {}

let myClass = MyClass()

print(myClass.conforms(to: UITableViewDelegate.self))
// prints false 

let viewController = myClass as UIViewController
print(viewController as? UITableViewDelegate ?? "not a delegate")
// prints not a delegate

If anyone knows why this is happening or how to properly check this conformance that'd be great

2 Answers 2

2

In Swift 3, adding @objc to my MyProtocol works.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome thanks, it appears this is a swift 3.1 Xcode 8.3.X issue
1

Why it's true for me(tested with Swift 3.2 and 4.0), did we really do the same thing:

enter image description here

2 Comments

Yep I was doing the same thing, you are right this is fixed for 3.2 & 4. I was using swift 3.1
So that. Thanks for figuring it out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.