当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
LeetCode 283. 移动零(简单、数组)
59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)
Expert Insights | 3 ways to seize innovation opportunities in a downturn
CollectionUtil:一个函数式风格的集合工具
SQL执行顺序
返回文件名问题
【故障诊断分析】基于matlab FFT轴承故障诊断【含Matlab源码 2001期】
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
线程的创建方式
PMP新考纲通关秘籍,告别抓瞎
Resolving C# non-static field, method or property "islandnum.Program.getIslandCount(int[][], int, int)" requires an object reference
mysql 注入
新产品立大功 伟世通第二季度营收双增
责任链模式(Chain Of Responsibility)
SQL server 2014 怎么一次性导出多个查询结果?
C#重点问题之Struct和Class的异同
2022年数据泄露平均成本高达435万美元,创历史新高!
【故障诊断分析】基于matlab FFT轴承故障诊断(包络谱)【含Matlab源码 2002期】
SimpleChannelInboundHandler使用总结
【CNN回归预测】基于matlab卷积神经网络CNN数据回归预测【含Matlab源码 2003期】









