Coexistence with KVO. Yes, it works!! #115
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, @steipete
I loved aspects, and I really want it can be used by everyone in every projects. But I think the KVO crash is one of limitation which block the way.
So, I have spent many times(and in many ways) to making it works, and hopefully, I got a solution:
original _cmd
That means we need re-swizzle the
originalSelector
we saved priviously to class-isa and setinvocation.selector
with it also before calling[invocation invoke];
All things works like a charm.
KVO Coexistence with different aspects hook mode:
All tests above added/updated to the testCase target.
I can provide more detail about why this way has been choosen with this PR if you're interested.
One limitation:
Instance Hook after KVO
Doing instance hook on a KVO'ed class will trigger an in-place swizzle, then, the
forwardInvocation:
will be applied to the isa-swizzled subclass created by KVO. Aspects will works until the isa-swizzled subclass destoryed once all observer has been removed. As our usual practice, removes all observers indealloc
method. This is the same logic as RAC and it's acceptable I think.Many thanks for all your work on this project!