引入MLeaksFinder报错的解决办法

前段时间想导入 MLeaksFinder 看下内存泄露问题。

pod 'MLeaksFinder'

但是 pod install 之后项目编译报错了,Cannot initialize a parameter of type 'id<NSCopying> _Nonnull' with an rvalue of type 'Class'

解决办法是在 Podfile 里写入以下两段代码,重新 pod install 会将有问题的代码替换,就可以编译通过了。

post_install do |installer|
  ## Fix for XCode 12.5
  find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm",
    "layoutCache[currentClass] = ivars;", "layoutCache[(id<NSCopying>)currentClass] = ivars;")
  ## Fix for XCode 13.0
  find_and_replace("Pods/FBRetainCycleDetector/fishhook/fishhook.c",
                   "indirect_symbol_bindings[i] = cur->rebindings[j].replacement;",
                   "if (i < (sizeof(indirect_symbol_bindings) / sizeof(indirect_symbol_bindings[0]))) { \n indirect_symbol_bindings[i]=cur->rebindings[j].replacement; \n }")
end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
    text = File.read(name)
    replace = text.gsub(findstr,replacestr)
    if text != replace
        puts "Fix: " + name
        File.open(name, "w") { |file| file.puts replace }
        STDOUT.flush
    end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end
Built with Hugo
主题 StackJimmy 设计