FPRSelectorInstrumentor.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. NS_ASSUME_NONNULL_BEGIN
  16. /** This class is used to manage the swizzling of selectors on classes. An instance of this class
  17. * should be created for every selector that is being swizzled.
  18. */
  19. @interface FPRSelectorInstrumentor : NSObject
  20. /** The swizzled selector. */
  21. @property(nonatomic, readonly) SEL selector;
  22. /** Please use designated initializer. */
  23. - (instancetype)init NS_UNAVAILABLE;
  24. /** Initializes an instance of this class. The designated initializer.
  25. *
  26. * @note Capture the current IMP outside the replacing block which will be the originalIMP once we
  27. * swizzle.
  28. *
  29. * @param selector The selector pointer.
  30. * @param aClass The class to operate on.
  31. * @param isClassSelector YES specifies that the selector is a class selector.
  32. * @return An instance of this class.
  33. */
  34. - (instancetype)initWithSelector:(SEL)selector
  35. class:(Class)aClass
  36. isClassSelector:(BOOL)isClassSelector NS_DESIGNATED_INITIALIZER;
  37. /** Sets the instrumentor's replacing block. To be used in conjunction with initWithSelector:.
  38. *
  39. * @param block The block to replace the original implementation with. Make sure to call
  40. * originalImp in your replacing block.
  41. */
  42. - (void)setReplacingBlock:(id)block;
  43. /** The current IMP of the swizzled selector.
  44. *
  45. * @return The current IMP for the class, SEL of the FPRSelectorInstrumentor.
  46. */
  47. - (IMP)currentIMP;
  48. /** Swizzles the selector. */
  49. - (void)swizzle;
  50. /** Causes the original implementation to be run. */
  51. - (void)unswizzle;
  52. @end
  53. NS_ASSUME_NONNULL_END