InterposeKit icon indicating copy to clipboard operation
InterposeKit copied to clipboard

Support customizing reference type for Interpose object and bypass mode for Interpose initializer

Open ezoushen opened this issue 3 years ago • 0 comments

Thanks for your hard work and this AMAZING framework. This really saved me lots of time for dealing with the runtime, but I found that some of my needs couldn't be fulfilled without modifying the source code. So I opened this pull request discussing the possible solutions to solve the issues.

Customizing reference type

Issue

In my use case, I needed to make all hooks transparent thus I associate the interpose object with the hooked object. Obviously, it'll create a retain cycle.

Solution

I propose that we introduce a ObjectContainer that would hold the target object with customized reference type as I implemented in this pull request. So that we could initialize a Interpose object like

Interpose(object) // holding strong reference to the object by default
Interpose(.strong(object)) // holding strong reference to the object explicitly
Interpose(.weak(object)) // holding weak reference to the object
Interpose(.unowned(object)) // holding unowned reference to the object

Initializer bypass mode

Issue

In the designed initializer of Interpose class, it's forced to validating the posing and actual class of the target object, which is really nice for preventing some unwanted errors. But I would say that it should be an optional tool rather than a constraint while being fully aware of the risk by hooking a isa-swizzled object.

Solution

Add a bypass flag in initializers of Interpose class with default value true.

Interpose(object, bypass: true) // Will not validation
Interpose(object) // Will validate

ezoushen avatar Sep 24 '22 08:09 ezoushen