美文网首页
去除pod三方库中一部分不需要代码

去除pod三方库中一部分不需要代码

作者: Sweet丶 | 来源:发表于2022-03-22 14:42 被阅读0次

我们在使用一些三方库时,会遇到三方库中一部分文件无需使用的情况,这个时候我们为了包体积优化,需要去除它。比如AFNetworking:

  • 方法一:
    Podfile中
pod 'AFNetworking', '~> 3.0', :subspecs => ['Reachability', 'Serialization', 'Security', 'NSURLSession']
  • 方法二:
    Podfile中在pre_install中移除不需要的文件
pre_install do |installer|
    remove_afnetworking_uikit()
    remove_kingfisher_swiftui()
end

def remove_afnetworking_uikit
  # 包体积优化去掉AFNetworking中没用到的UIKit+AFNetworking文件夹中内容
  system("rm -rf ./Pods/AFNetworking/UIKit+AFNetworking")
end

def remove_kingfisher_swiftui
  # 解决 xcode13 Release模式下SwiftUI报错问题
  system("rm -rf ./Pods/Kingfisher/Sources/SwiftUI")
  code_file = "./Pods/Kingfisher/Sources/General/KFOptionsSetter.swift"
  code_text = File.read(code_file)
  code_text.gsub!(/#if canImport\(SwiftUI\) \&\& canImport\(Combine\)(.|\n)+#endif/,'')
  system("rm -rf " + code_file)
  aFile = File.new(code_file, 'w+')
  aFile.syswrite(code_text)
  aFile.close()
end

相关文章

网友评论

      本文标题:去除pod三方库中一部分不需要代码

      本文链接:https://www.haomeiwen.com/subject/stufjrtx.html