当前位置:网站首页>OC-Category
OC-Category
2022-08-02 07:49:00 【Peng classmate her deskmate】
The main purpose of a category is to prevent a class with many methods from being too long
It is possible to spread the methods in a class across multiple categories
A category belonging to a class can be seen as grouping the methods of a class
Usage
@interface class name (category name)
method declaration
@end
@implementation class name (category name)
method definition
@end
The main purpose is toDisperse many class methods in multiple categories Declare all categories in .h file but define different categories in different .m files
About adding a property declaration @property to a category
Attention!Variables cannot be directly declared in the declaration of the category, only by writing @property int a; then in the normal state @preperty will automatically define the set and get methods, but if the @property is declared in the category, it will not be automatically defined in the definitionCreate and cannot write @synthesize in the category definition, you need to manually implement it yourself because it prevents random access to instance variables defined in different files of the same class
About overriding the same method in multiple categories
The last edit (for example, adding a space to the method of this category) is the method in which category is to call the method in which category. The overridden method must be able to overwrite the original method (that is, in thethe one defined in the class)
A class extension is a category without a name
Class extension can declare instance variables but class extension can only declare
The implementation must only be in the main implementation
#interface A()//There is nothing to write in parentheses
{
int a;
}
-()say;
Linked references
Multiple references can be added to an object
Must use certain non-changing addresses as keys such as static local variables
import<objc/runtime>void objc-setAssociatedObject(id object,void *key,id value,objc_AssociationPolicy policy)
Add the address specified by key as the key value for the object object, associative reference with value as the value, plicy specifies the storage strategy of the associated reference
By specifying the value as nil, the association of the key can be deleted
id objc_getAssociatedObject(id object,void *key)
Returns the object associated with object with key as key If it is not associated with any object, it will return nil
Instance
边栏推荐
猜你喜欢
随机推荐
MySQL-FlinkCDC-Hudi实时入湖
数据库概论之MySQL表的增删改查2
返回文件名问题
The second day HCIP
About the SQL concat () function problem, how to splice
如何设计静态资源缓存方案
交换部分 VLAN
(2022牛客多校五)B-Watches(二分)
System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
MPLS的相关技术
Link with Game Glitch(spfa判负环)
A Preliminary Study on the Basic Principles of Formal Methods
“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL
Neo4j 中文开发者月刊 - 202207期
从云计算到函数计算
在VMware上安装Metasploitable2
【ROS基础】rosbag 的使用方法
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)
堡垒机、堡垒机的原理
暑假第五周总结









