Skip to content

Commit d635810

Browse files
committed
Removed guts from ClassHook
1 parent dee3e0c commit d635810

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

Sources/InterposeKit/Hooks/AnyHook.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,30 @@ public class AnyHook: Hook {
7979

8080
/// Hook baseclass with generic signatures.
8181
public class TypedHook<MethodSignature, HookSignature>: AnyHook {
82+
83+
override func replaceImplementation() throws {
84+
if let strategy = self.strategy as? ClassHookStrategy<MethodSignature> {
85+
return try strategy.replaceImplementation()
86+
} else {
87+
preconditionFailure("Not implemented")
88+
}
89+
}
90+
91+
override func resetImplementation() throws {
92+
if let strategy = self.strategy as? ClassHookStrategy<MethodSignature> {
93+
return try strategy.resetImplementation()
94+
} else {
95+
preconditionFailure("Not implemented")
96+
}
97+
}
98+
8299
/// The original implementation of the hook. Might be looked up at runtime. Do not cache this.
83100
public var original: MethodSignature {
84-
preconditionFailure("Always override")
101+
if let strategy = self.strategy as? ClassHookStrategy<MethodSignature> {
102+
return strategy.original
103+
} else {
104+
preconditionFailure("Not implemented")
105+
}
85106
}
107+
86108
}

Sources/InterposeKit/Hooks/ClassHook.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ extension Interpose {
2626
strategyProvider: strategyProvider
2727
)
2828
}
29-
30-
override func replaceImplementation() throws {
31-
try (self.strategy as! ClassHookStrategy<MethodSignature>).replaceImplementation()
32-
}
33-
34-
override func resetImplementation() throws {
35-
try (self.strategy as! ClassHookStrategy<MethodSignature>).resetImplementation()
36-
}
37-
38-
/// The original implementation is cached at hook time.
39-
public override var original: MethodSignature {
40-
(self.strategy as! ClassHookStrategy<MethodSignature>).original
41-
}
4229

4330
}
4431
}

0 commit comments

Comments
 (0)