<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

       

      + (void)initialize
      {
          if (self == [MyViewController class]) {
              
              // 獲取原始方法和替代方法
              Method originalMethod = class_getInstanceMethod([self class], @selector(viewDidLoad));
              Method swizzledMethod = class_getInstanceMethod([self class], @selector(xxx_viewDidLoad));
              // 執行方法交換
              method_exchangeImplementations(originalMethod, swizzledMethod);
          }
      }
      
      // 新的 viewDidLoad 實現
      - (void)xxx_viewDidLoad {
          // 在原始 viewDidLoad 之前執行你自定義的行為
          NSLog(@"viewDidLoad is called");
          
          // 調用原始 viewDidLoad(因為方法交換了,實際上是調用原來的 viewDidLoad)
          [self xxx_viewDidLoad];
      }

       

      OC版本

      + (void)hookClass:(Class)cls originalSelector:(SEL)orlSelector swizzledSelector:(SEL)swzdSelector {
          Method originalMethod = class_getInstanceMethod(cls, orlSelector);
          Method swizzledMethod = class_getInstanceMethod(cls, swzdSelector);
          if (class_addMethod(self, orlSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))) {
              class_replaceMethod(self, swzdSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
          } else {
              method_exchangeImplementations(originalMethod, swizzledMethod);
          }
      }

       

      OC版應用實例方法替換  用自己的zf_dealloc 替換系統的dealloc

      + (void)initialize {
          static dispatch_once_t onceToken;
          dispatch_once(&onceToken, ^{
              SEL selectors[] = {
                  NSSelectorFromString(@"dealloc")
              };
              
              for (NSInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {
                  SEL originalSelector = selectors[index];
                  SEL swizzledSelector = NSSelectorFromString([@"zf_" stringByAppendingString:NSStringFromSelector(originalSelector)]);
                  Method originalMethod = class_getInstanceMethod(self, originalSelector);
                  Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector);
                  if (class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))) {
                      class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
                  } else {
                      method_exchangeImplementations(originalMethod, swizzledMethod);
                  }
              }
          });
      }
      
      - (void)zf_dealloc {
          [self.smallFloatView removeFromSuperview];
          self.smallFloatView = nil;
          [self zf_dealloc];
      }

       

       

      Swift版本

      // MARK: - 三、Hook
      @objc public extension NSObject {
          /// 實例方法替換
          static func hookInstanceMethod(of origSel: Selector, with replSel: Selector) -> Bool {
              let clz: AnyClass = classForCoder()
              guard let oriMethod = class_getInstanceMethod(clz, origSel) as Method? else {
                  JKPrint("原 實例方法:Swizzling Method(\(origSel)) not found while swizzling class \(NSStringFromClass(classForCoder())).")
                  return false
              }
              
              guard let repMethod = class_getInstanceMethod(clz, replSel) as Method? else {
                  JKPrint("新 實例方法:Swizzling Method(\(replSel)) not found while swizzling class \(NSStringFromClass(classForCoder())).")
                  return false
              }
              
              // 在進行 Swizzling 的時候,需要用 class_addMethod 先進行判斷一下原有類中是否有要替換方法的實現
              let didAddMethod: Bool = class_addMethod(clz, origSel, method_getImplementation(repMethod), method_getTypeEncoding(repMethod))
              // 如果 class_addMethod 返回 yes,說明當前類中沒有要替換方法的實現,所以需要在父類中查找,這時候就用到 method_getImplemetation 去獲取 class_getInstanceMethod 里面的方法實現,然后再進行 class_replaceMethod 來實現 Swizzing
              if didAddMethod {
                  class_replaceMethod(clz, replSel, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod))
              } else {
                  method_exchangeImplementations(oriMethod, repMethod)
              }
              return true
          }
          
          /// 類方法替換
          static func hookClassMethod(of origSel: Selector, with replSel: Selector) -> Bool {
              let clz: AnyClass = classForCoder()
              
              guard let oriMethod = class_getClassMethod(clz, origSel) as Method? else {
                  JKPrint("原 類方法:Swizzling Method(\(origSel)) not found while swizzling class \(NSStringFromClass(classForCoder())).")
                  return false
              }
              
              guard let repMethod = class_getClassMethod(clz, replSel) as Method? else {
                  JKPrint("新 類方法 replSel:Swizzling Method(\(replSel)) not found while swizzling class \(NSStringFromClass(classForCoder())).")
                  return false
              }
              
              // 在進行 Swizzling 的時候,需要用 class_addMethod 先進行判斷一下原有類中是否有要替換方法的實現
              let didAddMethod: Bool = class_addMethod(clz, origSel, method_getImplementation(repMethod), method_getTypeEncoding(repMethod))
              // 如果 class_addMethod 返回 yes,說明當前類中沒有要替換方法的實現,所以需要在父類中查找,這時候就用到 method_getImplemetation 去獲取 class_getInstanceMethod 里面的方法實現,然后再進行 class_replaceMethod 來實現 Swizzing
              if didAddMethod {
                  class_replaceMethod(clz, replSel, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod))
              } else {
                  method_exchangeImplementations(oriMethod, repMethod)
              }
              return true
          }
          
          /// 方法替換
          static func hookMethod(of origSel: Selector, with replSel: Selector, isClassMethod: Bool) -> Bool {
              let clz: AnyClass = classForCoder()
              
              guard let oriMethod = (isClassMethod ? class_getClassMethod(clz, origSel) : class_getClassMethod(clz, origSel)) as Method?,
                    let repMethod = (isClassMethod ? class_getClassMethod(clz, replSel) : class_getClassMethod(clz, replSel)) as Method?
              else {
                  JKPrint("Swizzling Method(s) not found while swizzling class \(NSStringFromClass(classForCoder())).")
                  return false
              }
              
              // 在進行 Swizzling 的時候,需要用 class_addMethod 先進行判斷一下原有類中是否有要替換方法的實現
              let didAddMethod: Bool = class_addMethod(clz, origSel, method_getImplementation(repMethod), method_getTypeEncoding(repMethod))
              // 如果 class_addMethod 返回 yes,說明當前類中沒有要替換方法的實現,所以需要在父類中查找,這時候就用到 method_getImplemetation 去獲取 class_getInstanceMethod 里面的方法實現,然后再進行 class_replaceMethod 來實現 Swizzing
              if didAddMethod {
                  class_replaceMethod(clz, replSel, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod))
              } else {
                  method_exchangeImplementations(oriMethod, repMethod)
              }
              return true
          }
      }

       

      posted on 2025-06-05 10:21  懂事長qingzZ  閱讀(18)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 亚洲 日本 欧洲 欧美 视频| 老司机午夜精品视频资源| 欧美日韩在线亚洲二区综二| 国产老熟女视频一区二区| chinese极品人妻videos| 极品尤物被啪到呻吟喷水| 国产超碰人人做人人爱| 色窝窝免费播放视频在线| 久久香蕉欧美精品| 久久一日本道色综合久久| 天天爽天天摸天天碰| 国产精品中文一区二区| 临西县| 蜜桃成人无码区免费视频网站 | 婷婷99视频精品全部在线观看| 妓女妓女一区二区三区在线观看| 亚洲VA成无码人在线观看天堂| 安仁县| 中国性欧美videofree精品| 精品自拍自产一区二区三区| 精品无码一区二区三区爱欲| 无套内谢少妇一二三四| 国产精品成| 丰满人妻一区二区三区高清精品| 欧美成人精品三级在线观看| 久久自己只精产国品| 一区二区亚洲人妻精品| 国产日韩精品欧美一区喷水| 久久妇女高潮喷水多| 亚洲av日韩在线资源| 国内精品久久久久精免费| 少妇撒尿一区二区在线视频| 亚洲国产午夜精品福利| 久久精品亚洲中文无东京热| 国产一区二区三区小说| 亚洲人成人日韩中文字幕| 中文字幕日韩国产精品| 久爱无码精品免费视频在线观看 | 日本高清在线观看WWW色| 国产日韩成人内射视频| 久久人搡人人玩人妻精品|