問題:Xcode13 Kingfisher糟袁、RealmSwift Release模式編譯報錯
其中:Xcode13,Kingfisher,RealmSwift,Swift UI
Xcode 13 發(fā)行說明中提到:
Swift 庫可能無法為使用 armv7 的 iOS 目標(biāo)構(gòu)建判族。(74120874) 解決方法:將包的平臺依賴性增加到 v12 或更高版本。 依賴于 Combine 的 Swift 庫可能無法為包括 armv7 和 i386 架構(gòu)在內(nèi)的目標(biāo)構(gòu)建项戴。(82183186, 82189214) 解決方法:使用不受影響的庫的更新版本(如果可用)或刪除 armv7 和 i386 支持( 例如形帮,將庫的部署目標(biāo)增加到 iOS 11 或更高版本)。
Kingfisher
周叮、RealmSwift
庫處于上述情況辩撑,如果項目中使用的是 Swift UI
則需要將最低兼容版本改為iOS 12
。由于個人項目需要兼容 iOS 10 并且項目中也沒有使用到 Swift UI仿耽,所以修改 pod file
合冀,在 pod install 時將Kingfisher、RealmSwift庫的 Swift UI 相關(guān)代碼刪除氓仲。
image.png
pre_install do |installer|
remove_Kingfisher_swiftui()
remove_RealmSwift_swiftui()
end
def remove_Kingfisher_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/,'')
file = File.new(code_file, 'w+')
file.syswrite(code_text)
file.close()
end
def remove_RealmSwift_swiftui
code_file = "./Pods/RealmSwift/RealmSwift/SwiftUI.swift"
code_text = File.read(code_file)
code_text.gsub!(/#if canImport\(SwiftUI\) \&\& canImport\(Combine\)(.|\n)+#else/,'')
code_text = code_text.gsub(/#endif/,'')
file = File.new(code_file, 'w+')
file.syswrite(code_text)
file.close()
end
在 Ruby 中 gsub 函數(shù)用于替換字符水慨,示例用法如下:
'abc'.gsub(/a/,d) => 'dbc'
'abc'.gsub!(/a/,d) => 'dbc'
'abc'.gsub(/d/,e) => 'abc'
'abc'.gsub!(/d/,e) => nil
若有其他第三方庫遇到這種情況,可以嘗試根據(jù)上面的示例編寫對應(yīng)函數(shù)敬扛,刪除 Swift UI 代碼。