Getting started with iOS development☞OC language · note 7, iosoc
Category
Categories can only be added to class extension methods. Attributes cannot be added!
@ Interface Class Name (category name) // Declare the Extension Method @ End |
@ Implementation Class Name (category name) // Method for implementing Expansion @ End |
Create a category:
Classification considerations:
- A category is used to add methods to the original class. It can only add methods, but cannot add attributes (member variables)
- Define the @ property attribute in the category. Only the declaration of the setter/getter method is generated, and the implementation of the method and instance variables are not generated.
- You can access the attributes in. h of the original class in the category.
Call Sequence of methods: 1. Category> 2. Category> 3. parent class
Extended Extension
Anonymous classification defines extensions in the. m file of the class, and defines private attributes and private methods in extensions.
@ Interface Class Name () // Declare private member variables // Declare private attributes // Declare a private Method @ End |
- The most common extension method is:
Define extensions in the. m file of the class, define private attributes in extensions, and declare private methods.
You can use extensions in the UI to define private attributes!
Category exercise: