Aspects icon indicating copy to clipboard operation
Aspects copied to clipboard

Add selector for optional method from protocol

Open pronebird opened this issue 8 years ago • 2 comments

Is it possible to add instance method that may not be defined on target class but defined in protocol as optional?

Currently -aspect_hookSelector reports that it cannot find selector.

p.s.: Adding empty method implementation solves the problem.

pronebird avatar Oct 08 '15 10:10 pronebird

Hmmm, could be done with an additional option to kill the check and add some logic to not call super. Would confuse people thought that would dynamically add methods after a delegate has been set, since most of UIKit caches what selectors are available at delegate set time.

On 08 Oct 2015, at 12:35, Andrey Mikhaylov [email protected] wrote:

Is it possible to add instance method that may not be defined on target class but defined in protocol as optional?

Currently -aspect_hookSelector reports that it cannot find selector.

― Reply to this email directly or view it on GitHub.

steipete avatar Oct 08 '15 11:10 steipete

It should be safe to add method on class-level as opposed to swizzling on instance level. How do you even call that kind of swizzling? Still instance method in the end right?

[MyTestsDetailController aspect_hookSelector:@selector(magicMethodDefinedInProtocolButNotImplementedAtAll:) ...]

as opposed to:

auto myViewController = [[MyTestsDetailController alloc] init];
[myViewController aspect_hookSelector:...]

As a workaround I've defined an empty method implementation on my view controller.

pronebird avatar Oct 08 '15 11:10 pronebird