• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 01:08:23 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

使用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);



Best Answer-推荐答案


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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap