Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ezoushen
Copy link

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 ezoushen force-pushed the feature/reference-type branch 2 times, most recently from 0d00f0d to 6eef7be Compare September 29, 2022 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant