当前位置:网站首页>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
边栏推荐
猜你喜欢

论文《Deep Multifaceted Transformers for Multi-objective Ranking in Large-Scale E-commerce Recommender》

(2022牛客多校五)B-Watches(二分)

File upload vulnerability (2)

实验7 MPLS实验

The second day HCIP
![带手续费买卖股票的最大利益[找DP的状态定义到底缺什么?]](/img/14/cd6ed7452230571db2e027f61dbdba.png)
带手续费买卖股票的最大利益[找DP的状态定义到底缺什么?]

【CNN回归预测】基于matlab卷积神经网络CNN数据回归预测【含Matlab源码 2003期】

张驰咨询:企业实施精益管理的最大障碍,只把精益作为一种工具和方法

实例030:回文数

入门opencv,欢笑快乐每一天
随机推荐
数据库概论之MySQL表的增删改查2
Splunk Filed extraction 字段截取
解决:- SPY: No data found for this date range, symbol may be delisted报错
倍福使用AdsRemote组件实现和C#的ADS通讯
PMP新考纲考试内容介绍
OC-NSString
(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints
mysql 注入
吃透Chisel语言.30.Chisel进阶之通信状态机(二)——FSMD:以Popcount为例
JS初识高阶函数和函数柯里化
Resolving C# non-static field, method or property "islandnum.Program.getIslandCount(int[][], int, int)" requires an object reference
Swagger的简单介绍,集成,以及如何在生产环境中关闭swagger,在测试和开发环境中自动打开
OC-错误提示
Xilinx约束学习笔记—— 时序约束
optional
The second day HCIP
PMP新考纲通关秘籍,告别抓瞎
每周推荐短视频:为什么产品开发需要数字化?如何做到数字化?
LeetCode 283. 移动零(简单、数组)
Leetcode Weekly 304