Q:

How to know this NSObject is class or protocol in swift?

In swift , super class and protocol is write together like this

Most of times ,this will not make misunderstanding , But because there is a NSObject class and a NSObject protocol with the same name, How to distinguish them?

And how the compiler know to use the NSObject class not the NSObject protocol?
And If I want to use the NSObject protocol not the NSObject class , how to write the class declaration?

A:

The protocol is called NSObjectProtocol not NSObject which is a class. If you want something to conform to NSObjectProtocol exclusively use that:
protocol MyProtocol: NSObjectProtocol { }

On the other hand NSObject conforms to NSObjectProtocol. So in conclusion by inheriting a class from NSObject means it's refering to the NSObject class and (not the NSObject objective-c @protocol) ipso facto conforms it to NSObjectProtocol.

