省钱达人

YYWeakProxy.m 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // YYWeakProxy.m
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 14/10/18.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import "YYWeakProxy.h"
  12. @implementation YYWeakProxy
  13. - (instancetype)initWithTarget:(id)target {
  14. _target = target;
  15. return self;
  16. }
  17. + (instancetype)proxyWithTarget:(id)target {
  18. return [[YYWeakProxy alloc] initWithTarget:target];
  19. }
  20. - (id)forwardingTargetForSelector:(SEL)selector {
  21. return _target;
  22. }
  23. - (void)forwardInvocation:(NSInvocation *)invocation {
  24. void *null = NULL;
  25. [invocation setReturnValue:&null];
  26. }
  27. - (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
  28. return [NSObject instanceMethodSignatureForSelector:@selector(init)];
  29. }
  30. - (BOOL)respondsToSelector:(SEL)aSelector {
  31. return [_target respondsToSelector:aSelector];
  32. }
  33. - (BOOL)isEqual:(id)object {
  34. return [_target isEqual:object];
  35. }
  36. - (NSUInteger)hash {
  37. return [_target hash];
  38. }
  39. - (Class)superclass {
  40. return [_target superclass];
  41. }
  42. - (Class)class {
  43. return [_target class];
  44. }
  45. - (BOOL)isKindOfClass:(Class)aClass {
  46. return [_target isKindOfClass:aClass];
  47. }
  48. - (BOOL)isMemberOfClass:(Class)aClass {
  49. return [_target isMemberOfClass:aClass];
  50. }
  51. - (BOOL)conformsToProtocol:(Protocol *)aProtocol {
  52. return [_target conformsToProtocol:aProtocol];
  53. }
  54. - (BOOL)isProxy {
  55. return YES;
  56. }
  57. - (NSString *)description {
  58. return [_target description];
  59. }
  60. - (NSString *)debugDescription {
  61. return [_target debugDescription];
  62. }
  63. @end