Source of the problem:
Common Interview Questions:
NSObject and NSObject protocol What is the difference, why should have nsobject protocol, have not inherited from NSObject class?
Although almost all of the classes used in the iOS development process derive from NSObject, cocoa is not the only one with the root class NSObject. Another typical root class is nsproxy. This is why you need to define both the NSObject class and the NSObject protocol. Those classes that are not derived from NSObject can also implement NSObject protocol. In other words, NSObject class and NSObject protocol themselves are independent of each other, according to the normal understanding of the class and understanding of the agreement to understand the matter can be. Of course, the necessity of the NSObject protocol protocol exists because not all classes derive from NSObject.
In the definition of nsprotocol, there are the following methods:
-(BOOL) isproxy;
This method can be used to determine whether the class is derived from another root class.
The documentation is described below:
|
-(BOOL) IsProxy |
|
Description |
Returns a Boolean value that indicates whether the receiver does not descend from nsobject. (required) |
|
|
This method was necessary because sending Iskindofclass: or Ismemberofclass: to an nsproxy objec T test the object the proxy stands in for, not the proxy itself. Use this method to test if the receiver was a proxy (or a member of some other root class). |
|
Returns |
NO If the receiver really descends from nsobject, otherwise YES. |
As for the nsproxy itself, it is generally less used in iOS development. Nsproxy can be used to implement proxy mode and simulate multiple inheritance, specifically, see the following blog post:
Implementing proxy Mode with Nsproxy: http://blog.csdn.net/onlyou930/article/details/7548476
Using Nsproxy to implement the message forwarding mechanism to simulate multiple inheritance: http://blog.csdn.net/onlyou930/article/details/7548634
Also the following article detailed description of NSObject class and NSObject protocol, I am more lazy, directly affixed to the link:
Original: Nsobject:the Class and the Protocol https://mikeash.com/pyblog/ Friday-qa-2013-10-25-nsobject-the-class-and-the-protocol.html
Translation: http://my.oschina.net/yongbin45/blog/202535
IOS Root Class