IOS Root Class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.