我们在使用一些三方库时,会遇到三方库中一部分文件无需使用的情况,这个时候我们为了包体积优化,需要去除它。比如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
网友评论