gpt4 book ai didi

ios - 运行时 - 这个 "@@:"在 class_addMethod 中意味着什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:24:50 25 4
gpt4 key购买 nike

使用class_addMethod代码:

class_addMethod(newClass, @selector(inputAccessoryView), accessoryImp, "@@:");

这个方法中参数“@@:”是什么意思?

文档:

/** 
* Adds a new method to a class with a given name and implementation.
*
* @param cls The class to which to add a method.
* @param name A selector that specifies the name of the method being added.
* @param imp A function which is the implementation of the new method. The function must take at least two arguments—self and _cmd.
* @param types An array of characters that describe the types of the arguments to the method.
*
* @return YES if the method was added successfully, otherwise NO
* (for example, the class already contains a method implementation with that name).
*
* @note class_addMethod will add an override of a superclass's implementation,
* but will not replace an existing implementation in this class.
* To change an existing implementation, use method_setImplementation.
*/
OBJC_EXPORT BOOL class_addMethod(Class cls, SEL name, IMP imp,
const char *types)
OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);

最佳答案

types 参数描述了参数和返回类型方法如中所述 class_addMethod :

An array of characters that describe the types of the arguments to the method. For possible values, see Objective-C Runtime Programming Guide > Type Encodings. Since the function must take at least two arguments— self and _cmd, the second and third characters must be “@:” (the first character is the return type).

"@@:" 描述了一个返回对象的方法(类型编码 @,在您的情况下:UIView *)并且除了固定(隐藏)参数 self(类型编码 @ 用于对象)和 _cmd(类型编码 : 用于选择器)。

关于ios - 运行时 - 这个 "@@:"在 class_addMethod 中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43492021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com