Objective-C Delegate Type

2019-02-28 04:10发布

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?

If its expected to be DelegateName, and it wasn't how would you change it manually?

EDIT:

@protocol NavigationBarDelegate @optional - (void)titleViewClicked:(BOOL)titleClicked; @end

po output in LLDB:

(lldb) po self.delegate
(objc_object *) $1 = 0x073d0840 <UINavigationController: 0x73d0840>

As a result, the delegate is being sent to a UINavigationController as opposed to the intended class.

1条回答
放我归山
2楼-- · 2019-02-28 04:28

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.

查看更多
登录 后发表回答