Skip to content

Commit

Permalink
fix supportsSecureCoding for intercepted classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bamx23 committed Jul 31, 2019
1 parent 4e42994 commit 6224bee
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Classes/Stubbing/KWIntercept.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
void KWInterceptedDealloc(id anObject, SEL aSelector);
Class KWInterceptedClass(id anObject, SEL aSelector);
Class KWInterceptedSuperclass(id anObject, SEL aSelector);
BOOL KWInterceptedSupportsSecureCodingTrue(id anObject, SEL aSelector);
BOOL KWInterceptedSupportsSecureCodingFalse(id anObject, SEL aSelector);

#pragma mark - Getting Forwarding Implementations

Expand Down Expand Up @@ -120,6 +122,15 @@ Class KWInterceptClassForCanonicalClass(Class canonicalClass) {
Class interceptMetaClass = object_getClass(interceptClass);
class_addMethod(interceptMetaClass, @selector(forwardInvocation:), (IMP)KWInterceptedForwardInvocation, "v@:@");

SEL supportsSecureCodingSelector = @selector(supportsSecureCoding);
Method supportsSecureCodingMethod = class_getClassMethod(canonicalClass, supportsSecureCodingSelector);
if (supportsSecureCodingMethod != NULL) {
BOOL support = [(id)canonicalClass performSelector:supportsSecureCodingSelector];
IMP supportsSecureCodingIMP = support ? (IMP)KWInterceptedSupportsSecureCodingTrue
: (IMP)KWInterceptedSupportsSecureCodingFalse;
class_addMethod(interceptMetaClass, supportsSecureCodingSelector, supportsSecureCodingIMP, "B@:");
}

return interceptClass;
}

Expand Down Expand Up @@ -223,6 +234,14 @@ Class KWInterceptedSuperclass(id anObject, SEL aSelector) {
return originalSuperclass;
}

BOOL KWInterceptedSupportsSecureCodingTrue(id anObject, SEL aSelector) {
return YES;
}

BOOL KWInterceptedSupportsSecureCodingFalse(id anObject, SEL aSelector) {
return NO;
}

#pragma mark - Managing Objects Stubs

void KWAssociateObjectStub(id anObject, KWStub *aStub, BOOL overrideExisting) {
Expand Down

0 comments on commit 6224bee

Please sign in to comment.