当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Unity Shader学习(七)纹理图像的简单使用
每周推荐短视频:为什么产品开发需要数字化?如何做到数字化?
实验7 MPLS实验
Expert Insights | 3 ways to seize innovation opportunities in a downturn
线程的创建方式
mysql 注入
笔记本开机黑屏提示:ERROR 0199:System Security-Security password retry count exceeded
【ROS基础】map、odom、base_link、laser 的理解 及其 tf 树的理解
技术管理三级跳
敏捷、DevOps和嵌入式系统测试
队列题目:无法吃午餐的学生数量
返回文件名问题
解决Pytorch模型在Gunicorn部署无法运行或者超时问题
【暑期每日一题】洛谷 P1551 亲戚
概率论与数理统计
59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)
Leetcode Weekly 304
带手续费买卖股票的最大利益[找DP的状态定义到底缺什么?]
实例032:反向输出II
Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing