1. @interface can achieve three functions: (1) Declaring Class: Class (2) Declaration Category: Category (3) Declaration extension: Extension
2. Declare class : This is more commonly used, here not to say more. Code: @interface someclass:nsobject <somedelegate>{} @end
3. Declaration Category : (1) Categories can add methods to classes or override classes without changing the original class code. (2) A category can only add or override methods, but it cannot add variables. (3) A netizen said that the category name set to "private", can make the method of adding the category become a private method, this is not tenable (after the actual code validation). (4) If you are overriding a method that already exists for a class, the overridden method takes effect throughout the running environment and does not need to import the implementation class where it is used, or if you add a new method to the class, you need to import it where you want. (5) Code: @interface ClassName (category name) {} @end
4. Declaration extension: (1) The difference between extension and category syntax is simple, that is, the class name is omitted and only parentheses are retained. (2) The extension simply adds a declaration of the methods and variables of the original class, but does not include an implementation, so the extension does not have an independent implementation (@implementation), but rather shares an implementation with the original class. (3) The extension can not only increase the method on the basis of the original class, but also increase the variable. (4) If the extension is written to the implementation file, the added variables and methods are private and private. (5) Code: @interface ClassName () {} @end
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