@@ -27,11 +27,14 @@ extension NSObject {
2727 /// - action: Action to perform when `selector` was triggered
2828 public func setInterceptionHandler(
2929 for selector: Selector ,
30- key: AnyHashable = " __default_handler__ " ,
30+ key: AnyHashable ? = nil ,
3131 action: ( ( InterceptionResult < Any , Any > ) -> Void ) ?
3232 ) {
3333 let handler = _intercept ( selector)
34- handler. register ( action. map ( SimpleInterceptionHandler . init) , for: key)
34+ handler. register (
35+ action. map ( SimpleInterceptionHandler . init) ,
36+ for: SwiftInterceptionDefaultInterceptionHandlerKey . unwrap ( key)
37+ )
3538 }
3639
3740 /// Sets interception handler, which accepts ``InterceptionResult`` containing a tuple
@@ -45,13 +48,13 @@ extension NSObject {
4548 /// - action: Action to perform when `selector` was triggered
4649 public func setInterceptionHandler< Args, Output> (
4750 for selector: _MethodSelector < Args , Output > ,
48- key: AnyHashable = " __default " ,
51+ key: AnyHashable ? = nil ,
4952 action: ( ( InterceptionResult < Args , Output > ) -> Void ) ?
5053 ) {
5154 let handler = _intercept ( selector. wrappedValue)
5255
5356 guard let action else {
54- handler. register ( nil , for: key)
57+ handler. register ( nil , for: SwiftInterceptionDefaultInterceptionHandlerKey . unwrap ( key) )
5558 return
5659 }
5760
@@ -62,7 +65,7 @@ extension NSObject {
6265 output: Output . self
6366 ) )
6467 } ,
65- for: key
68+ for: SwiftInterceptionDefaultInterceptionHandlerKey . unwrap ( key)
6669 )
6770 }
6871
@@ -322,6 +325,17 @@ private func setupMethodSignatureCaching(_ realClass: AnyClass, _ signatureCache
322325 )
323326}
324327
328+ @_spi ( Internals)
329+ public struct SwiftInterceptionDefaultInterceptionHandlerKey : Hashable {
330+ public static let shared : Self = . init( )
331+
332+ private init ( ) { }
333+
334+ public static func unwrap( _ key: AnyHashable ? ) -> AnyHashable {
335+ key ?? Self . shared as AnyHashable
336+ }
337+ }
338+
325339@_spi ( Internals)
326340public protocol InterceptionHandlerProtocol {
327341 func handle( _ result: InterceptionResult < Any , Any > )
0 commit comments