有一種BUG叫莫名其妙
有一種堅(jiān)持叫注釋調(diào)試
有一種原因叫原來如此
終于要進(jìn)行適配swift和最低版本支持到iOS10驰后,也使用上Bitcode,心里好舒坦了状原。在新增加的代碼使用swift后出現(xiàn)了莫名其妙的bug菩收,問了度娘也說不清楚啊拨齐,或者給了一些似是而非的答案驰贷,全部試過了還是沒有解決摘盆。
報(bào)錯(cuò)
編寫好代碼后,一直在報(bào)錯(cuò)饱苟。
3. While emitting IR SIL function "@$s10Dispatcher27HXRidingBikesViewControllerC03mapD0_9didSelectySo05MAMapD0CSg_So012MAAnnotationD0CSgtF".
for 'mapView(_:didSelect:)' (at 這里是目錄RidingBikesViewController.swift:453:5)
0 swift 0x000000010dee34ea PrintStackTraceSignalHandler(void*) + 42
1 swift 0x000000010dee2cc0 SignalHandler(int) + 352
2 libsystem_platform.dylib 0x00007fff6b83b5fd _sigtramp + 29
3 libsystem_platform.dylib 0x00007ffee6068130 _sigtramp + 2055392080
4 swift 0x0000000109e19689 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::packIntoEnumPayload(swift::irgen::IRGenFunction&, swift::irgen::EnumPayload&, swift::irgen::Explosion&, unsigned int) const + 121
5 swift 0x0000000109e19689 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::packIntoEnumPayload(swift::irgen::IRGenFunction&, swift::irgen::EnumPayload&, swift::irgen::Explosion&, unsigned int) const + 121
6 swift 0x0000000109e19689 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::packIntoEnumPayload(swift::irgen::IRGenFunction&, swift::irgen::EnumPayload&, swift::irgen::Explosion&, unsigned int) const + 121
7 swift 0x0000000109e19689 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::packIntoEnumPayload(swift::irgen::IRGenFunction&, swift::irgen::EnumPayload&, swift::irgen::Explosion&, unsigned int) const + 121
8 swift 0x0000000109d31e99 (anonymous namespace)::SinglePayloadEnumImplStrategy::emitValueInjection(swift::irgen::IRGenFunction&, swift::EnumElementDecl*, swift::irgen::Explosion&, swift::irgen::Explosion&) const + 297
9 swift 0x0000000109e76d1b swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 38795
10 swift 0x0000000109e6a053 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8835
11 swift 0x0000000109d1d722 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1410
12 swift 0x0000000109e48649 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1097
13 swift 0x0000000109c3fa5f performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 4255
14 swift 0x0000000109c34eba swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48426
15 swift 0x0000000109bacb73 main + 1283
16 libdyld.dylib 0x00007fff6b642cc9 start + 1
error: Segmentation fault: 11 (in target 'Dispatcher' from project 'dispatch')
報(bào)錯(cuò)的位置指向了
func mapView(_ mapView: MAMapView!, didSelect view: MAAnnotationView!)
這有什么錯(cuò)呢,下載了高德地圖的實(shí)例后狼渊,發(fā)現(xiàn)也是一樣的寫法啊箱熬。
排查思路:
- Bitcode關(guān)閉 (失敗)
- 刪除整片代碼 (編譯通過狈邑,可以確認(rèn)這塊代碼有問題)
- 配置項(xiàng)比對(duì) (失敗 與高德地圖實(shí)例都保持一致)
- Valid Architectures修改 (當(dāng)添加armv7時(shí)城须,編譯失敗,其他編譯成功)
- 注解代碼米苹,找到問題所在的代碼
解決
步步為營(yíng)糕伐,層層排查后,已經(jīng)確定問題是出現(xiàn)在armv7架構(gòu)的支持上蘸嘶,代碼是在
func mapView(_ mapView: MAMapView!, didSelect view: MAAnnotationView!) {
let anno: MAAnnotation = view.annotation
if !(anno.isKind(of: MAUserLocation.classForCoder())) {
view.transform = CGAffineTransform.init(scaleX: 1.2, y: 1.2)
}
if self.selectedBikeNumber == anno.subtitle {
return
}
self.selectedBikeNumber = anno.subtitle
if anno.isKind(of: MAPointAnnotation.classForCoder()) {
let bikeNo: String! = anno.subtitle ?? ""
let model = self.findBicycleWithBikeNumer(bikeNumber: bikeNo)
if nil == model {
return
}
// 保存中心點(diǎn)位置
let coordinate = mapView.centerCoordinate
if nil == self.lastCenterCoordinate {
self.lastCenterCoordinate = coordinate
}
// 單車詳情
self.bicycleNumberLabel.text = model?.bikeNumber
self.bicycleInfoView.isHidden = false
}
}
中的
self.selectedBikeNumber = anno.subtitle
分析原因?yàn)?code>anno.subtitle的類型為option類型String??良瞧,而private var selectedBikeNumber: String?
需要先解包后才能賦值陪汽。
解決方案就是:
self.selectedBikeNumber = anno.subtitle ?? ""
將anno.subtitle
解包后再賦值,編譯通過褥蚯。
篇外
以為已經(jīng)大功告成了挚冤,但是最后發(fā)現(xiàn)原來還有一個(gè)坑啊。
could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1200.0.22.8.0_0' Reader: '1103.0.32.62_0')', using libLTO version 'LLVM version 11.0.3, (clang-1103.0.32.62)' for architecture armv7
和
could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1200.0.22.8.0_0' Reader: '1103.0.32.62_0')', using libLTO version 'LLVM version 11.0.3, (clang-1103.0.32.62)' for architecture arm64
看字面的意思是bitcode的版本不是最新版本啊赞庶。
查看本地的版本
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
也就是說我Xcode的本地的版本是1103版本训挡,而需要1200版本來編譯才能成功進(jìn)行bitcode的編譯。那么原因應(yīng)該就是在依賴的第三方庫(kù)中有使用了1200版本編譯的歧强,所以才導(dǎo)致必須需要使用最新版本澜薄。
大概率是為即將推出的iOS14準(zhǔn)備的Xcode的beta版本來進(jìn)行編譯的。!_!
解決方法: 將第三方庫(kù)版本回退摊册。
// END swift的長(zhǎng)征第一步