Objective-C代表类型 [英] Objective-C Delegate Type
问题描述
在Objective-C中创建代理时,假定委托: id< DelegateName>委托
,什么是委托
的类型应该是什么?因此,在LLDB中运行 po delegete
或 po self.delegate
,预期结果是什么?
When creating delegates in Objective-C, assume delegate: id <DelegateName> delegate
, what is the delegate
's type supposed to be? So running po delegete
or po self.delegate
in LLDB, what is the expected outcome?
如果它预期是 DelegateName
,那么你不会手动更改它?
If its expected to be DelegateName
, and it wasn't how would you change it manually?
编辑:
@protocol NavigationBarDelegate
@optional
- (void)titleViewClicked :( BOOL)titleClicked;
@end
@protocol NavigationBarDelegate @optional - (void)titleViewClicked:(BOOL)titleClicked; @end
po
LLDB中的输出:
po
output in LLDB:
(lldb) po self.delegate
(objc_object *) $1 = 0x073d0840 <UINavigationController: 0x73d0840>
因此,代理被发送到一个 UINavigationController
而不是预期的类。
As a result, the delegate is being sent to a UINavigationController
as opposed to the intended class.
推荐答案
类型是 id
所以它可以是任何 Objective-C对象。 < DelegateName>
符号表示对象将符合 DelegateName
协议,但不影响其类型。
The type is id
so it can be any Objective-C object. The <DelegateName>
notation means that the object will conform to the DelegateName
protocol, but that does not affect its type.
这篇关于Objective-C代表类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!