added iOS source code
[wl-app.git] / iOS / Pods / GoogleUtilities / GoogleUtilities / MethodSwizzler / Private / GULSwizzler.h
1 /*
2  * Copyright 2018 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #import <Foundation/Foundation.h>
18
19 NS_ASSUME_NONNULL_BEGIN
20
21 /** This class handles the runtime manipulation necessary to instrument selectors. It stores the
22  *  classes and selectors that have been swizzled, and runs all operations on its own queue.
23  */
24 @interface GULSwizzler : NSObject
25
26 /** Manipulates the Objective-C runtime to replace the original IMP with the supplied block.
27  *
28  *  @param aClass The class to swizzle.
29  *  @param selector The selector of the class to swizzle.
30  *  @param isClassSelector A BOOL specifying whether the selector is a class or instance selector.
31  *  @param block The block that replaces the original IMP.
32  */
33 + (void)swizzleClass:(Class)aClass
34             selector:(SEL)selector
35      isClassSelector:(BOOL)isClassSelector
36            withBlock:(nullable id)block;
37
38 /** Restores the original implementation.
39  *
40  *  @param aClass The class to unswizzle.
41  *  @param selector The selector to restore the original implementation of.
42  *  @param isClassSelector A BOOL specifying whether the selector is a class or instance selector.
43  */
44 + (void)unswizzleClass:(Class)aClass selector:(SEL)selector isClassSelector:(BOOL)isClassSelector;
45
46 /** Returns the current IMP for the given class and selector.
47  *
48  *  @param aClass The class to use.
49  *  @param selector The selector to find the implementation of.
50  *  @param isClassSelector A BOOL specifying whether the selector is a class or instance selector.
51  *  @return The implementation of the selector in the runtime.
52  */
53 + (nullable IMP)currentImplementationForClass:(Class)aClass
54                                      selector:(SEL)selector
55                               isClassSelector:(BOOL)isClassSelector;
56
57 /** Returns the original IMP for the given class and selector.
58  *
59  *  @param aClass The class to use.
60  *  @param selector The selector to find the implementation of.
61  *  @param isClassSelector A BOOL specifying whether the selector is a class or instance selector.
62  *  @return The implementation of the selector in the runtime before any consumer or GULSwizzler
63  *          swizzled.
64  */
65 + (nullable IMP)originalImplementationForClass:(Class)aClass
66                                       selector:(SEL)selector
67                                isClassSelector:(BOOL)isClassSelector;
68
69 /** Checks the runtime to see if a selector exists on a class. If a property is declared as
70  *  @dynamic, we have a reverse swizzling situation, where the implementation of a method exists
71  *  only in concrete subclasses, and NOT in the superclass. We can detect that situation using
72  *  this helper method. Similarly, we can detect situations where a class doesn't implement a
73  *  protocol method.
74  *
75  *  @param selector The selector to check for.
76  *  @param aClass The class to check.
77  *  @param isClassSelector A BOOL specifying whether the selector is a class or instance selector.
78  *  @return YES if the method was found in this selector/class combination, NO otherwise.
79  */
80 + (BOOL)selector:(SEL)selector existsInClass:(Class)aClass isClassSelector:(BOOL)isClassSelector;
81
82 /** Returns a list of all Objective-C (and not primitive) ivars contained by the given object.
83  *
84  *  @param object The object whose ivars will be iterated.
85  *  @return The list of ivar objects.
86  */
87 + (NSArray<id> *)ivarObjectsForObject:(id)object;
88
89 @end
90
91 NS_ASSUME_NONNULL_END