iOS項目編譯 FBClassStrongLayout.mm
文件報以下錯誤
cannot initialize a parameter of type 'is<NSCopying>_Nonnull' with an rvalue of type 'Class'
原因
XCode 12.5 不支持之前的語法,導致之前可以編譯的文件到在XCode 12.5 上編譯報錯
由于作者尚未對這個問題進行處理,所以開發者只能閑自行處理,保證項目可以正常運行。
其需要修改的地方是將 "layoutCache[currentClass] = ivars;"
替換成 "layoutCache[(id)currentClass] = ivars;"
處理方式
由于很多項目是多人開發并且需要進行版本管理,直接修改代碼方式不是那么優雅,建議是直接在 Podfile
文件的末尾添加處理的代碼,確保團隊項目代碼的一致性。
post_install do|installer|
find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm","layoutCache[currentClass] = ivars;", "layoutCache[(id)currentClass] = ivars;")
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