iOS笔记-performSelector的探索

本文探讨了iOS中performSelector的使用,包括其官方文档的描述,它如何允许在运行时发送未确定的消息。核心信息表明,performSelector可用于调用私有属性和方法,并且在调用时需要注意返回值问题和数据类型限制。测试结果证明,对于公开属性和方法,performSelector与直接调用等效,但在编译时期不检查方法存在性,运行时才进行检查。
摘要由CSDN通过智能技术生成

官方文档介绍

- (id)performSelector:(SEL)aSelector;

Description

Sends a specified message to the receiver and returns the result of
the message. The performSelector: method is equivalent to sending an
aSelector message directly to the receiver. For example, the following
messages all do the same thing:

Listing 1

id aClone = [anObject copy];
id aClone = [anObject performSelector:@selector(copy)];
id aClone = [anObject performSelector:sel_getUid("copy")];

The performSelector: method allows you to send messages that aren’t
determined until run-time. This means that you can pass a variable
selector as the argument:

Listing 2

SEL aSelector = findTheAppropriateSelectorForTheCurrentSituation();
id returnedObject = [anObject performSelector:aSelector];
</
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值