当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
FaceBook社媒营销高效转化技巧分享
awk语法-01-基础语法(命令、选项、内部变量)
System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
_2_顺序表
获取间隔的日期列表工具类
(2022牛客多校五)B-Watches(二分)
hdu1752 copy
技术管理三级跳
Xilinx约束学习笔记—— 时序约束
查找最大的n个文件
分离轴定理SAT凸多边形精确碰撞检测
反射课后习题及做题记录
Splunk Field Caculated 计算字段
实例032:反向输出II
自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)
【红队】ATT&CK - 创建或修改系统进程实现持久化(更新ing)
实验8 VLAN综合实验
CollectionUtil:一个函数式风格的集合工具
埋点开发流程
jvm 二之 栈帧内部结构









