| 1 | 
           efrain | 
           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 | 
              | 
        
        
            | 
            | 
           15 | 
           #import <Foundation/Foundation.h>
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           NS_ASSUME_NONNULL_BEGIN
  | 
        
        
            | 
            | 
           18 | 
              | 
        
        
            | 
            | 
           19 | 
           /** This class is used to manage the swizzling of selectors on classes. An instance of this class
  | 
        
        
            | 
            | 
           20 | 
            *  should be created for every selector that is being swizzled.
  | 
        
        
            | 
            | 
           21 | 
            */
  | 
        
        
            | 
            | 
           22 | 
           @interface FPRSelectorInstrumentor : NSObject
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           /** The swizzled selector. */
  | 
        
        
            | 
            | 
           25 | 
           @property(nonatomic, readonly) SEL selector;
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
            | 
            | 
           27 | 
           /** Please use designated initializer. */
  | 
        
        
            | 
            | 
           28 | 
           - (instancetype)init NS_UNAVAILABLE;
  | 
        
        
            | 
            | 
           29 | 
              | 
        
        
            | 
            | 
           30 | 
           /** Initializes an instance of this class. The designated initializer.
  | 
        
        
            | 
            | 
           31 | 
            *
  | 
        
        
            | 
            | 
           32 | 
            *  @note Capture the current IMP outside the replacing block which will be the originalIMP once we
  | 
        
        
            | 
            | 
           33 | 
            *      swizzle.
  | 
        
        
            | 
            | 
           34 | 
            *
  | 
        
        
            | 
            | 
           35 | 
            *  @param selector The selector pointer.
  | 
        
        
            | 
            | 
           36 | 
            *  @param aClass The class to operate on.
  | 
        
        
            | 
            | 
           37 | 
            *  @param isClassSelector YES specifies that the selector is a class selector.
  | 
        
        
            | 
            | 
           38 | 
            *  @return An instance of this class.
  | 
        
        
            | 
            | 
           39 | 
            */
  | 
        
        
            | 
            | 
           40 | 
           - (instancetype)initWithSelector:(SEL)selector
  | 
        
        
            | 
            | 
           41 | 
                                      class:(Class)aClass
  | 
        
        
            | 
            | 
           42 | 
                            isClassSelector:(BOOL)isClassSelector NS_DESIGNATED_INITIALIZER;
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
           /** Sets the instrumentor's replacing block. To be used in conjunction with initWithSelector:.
  | 
        
        
            | 
            | 
           45 | 
            *
  | 
        
        
            | 
            | 
           46 | 
            *  @param block The block to replace the original implementation with. Make sure to call
  | 
        
        
            | 
            | 
           47 | 
            *      originalImp in your replacing block.
  | 
        
        
            | 
            | 
           48 | 
            */
  | 
        
        
            | 
            | 
           49 | 
           - (void)setReplacingBlock:(id)block;
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
           /** The current IMP of the swizzled selector.
  | 
        
        
            | 
            | 
           52 | 
            *
  | 
        
        
            | 
            | 
           53 | 
            *  @return The current IMP for the class, SEL of the FPRSelectorInstrumentor.
  | 
        
        
            | 
            | 
           54 | 
            */
  | 
        
        
            | 
            | 
           55 | 
           - (IMP)currentIMP;
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
            | 
            | 
           57 | 
           /** Swizzles the selector. */
  | 
        
        
            | 
            | 
           58 | 
           - (void)swizzle;
  | 
        
        
            | 
            | 
           59 | 
              | 
        
        
            | 
            | 
           60 | 
           /** Causes the original implementation to be run. */
  | 
        
        
            | 
            | 
           61 | 
           - (void)unswizzle;
  | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
           @end
  | 
        
        
            | 
            | 
           64 | 
              | 
        
        
            | 
            | 
           65 | 
           NS_ASSUME_NONNULL_END
  |