当前位置:网站首页>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
边栏推荐
- sql 远程访问链接服务器
- Splunk Field Caculated 计算字段
- 【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
- Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
- mysql 注入
- 【暑期每日一题】洛谷 P1551 亲戚
- 敏捷、DevOps和嵌入式系统测试
- 牛客编程题中——需要处理输入较大数的题目
- Day 4 of HCIP
- 【心电信号】基于matlab心率检测【含Matlab源码 1993期】
猜你喜欢
张驰课堂:六西格玛培训工具——箱线图
【云原生】如何快速部署Kubernetes
新产品立大功 伟世通第二季度营收双增
【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
交换--STP协议
雷达人体存在感应器方案,智能物联网感知技术,实时感应人体存在
C#重点问题之Struct和Class的异同
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人
数据库概论之MySQL表的增删改查2
随机推荐
OC-NSNumber和NSValue一般用来装箱拆箱
sql 远程访问链接服务器
【暑期每日一题】洛谷 P1192 台阶问题
The second day HCIP
修改apt-get源为国内镜像源
jvm 二之 栈帧内部结构
【网络】IP、子网掩码
Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
Neo4j 中文开发者月刊 - 202207期
责任链模式(Chain Of Responsibility)
实例031:字母识词
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)
新产品立大功 伟世通第二季度营收双增
企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人
实例029:反向输出
Xilinx约束学习笔记—— 时序约束
实例026:递归求阶乘
docker 安装mysql
[21天学习挑战赛——内核笔记](一)——设备树的概述(硬件、目标、效果、文件类型)
LeetCode 2312. 卖木头块