我在Xcode 9中工作。代码工作正常,但是当我在Xcode 10中使用相同的代码时,我会遇到编译时错误。
这是错误:
1. While emitting SIL for 'fetchConsumerRecommendations(completionHandler:failureHandler:)' at /Users/shahezad/Desktop/Newcode/foodkonnectconsumer-ios/Food/FirebaseManager.swift:2578:5
2. While silgen emitFunction SIL function "@$S4Food15FirebaseManagerC28fetchConsumerRecommendations17completionHandler07failureH0yySaySSGc_ys5Error_pSgctFZ".
for 'fetchConsumerRecommendations(completionHandler:failureHandler:)' at /Users/shahezad/Desktop/Newcode/foodkonnectconsumer-ios/Food/FirebaseManager.swift:2578:5
3. While silgen closureexpr SIL function "@$S4Food15FirebaseManagerC28fetchConsumerRecommendations17completionHandler07failureH0yySaySSGc_ys5Error_pSgctFZySo19FIRDocumentSnapshotCSg_AItcfU_".
for expression at [/Users/shahezad/Desktop/Newcode/foodkonnectconsumer-ios/Food/FirebaseManager.swift:2584:285 - line:2615:9] RangeText="{ (documentSnapshot, error) in
if error == nil {
if (documentSnapshot?.exists)!{
print("Consumer Recommendations - \(describing: documentSnapshot?.data())")
let dictOnboarding:NSDictionary = (documentSnapshot?.data())! as NSDictionary
print("\(dictOnboarding.allKeys)")
completionHandler(dictOnboarding.allKeys as! [String])
}
else{
completionHandler([])
}
}
else{
failureHandler(error)
}
}"
error: Segmentation fault: 11
我无法弄清楚代码的问题所在。
答案 0 :(得分:0)
此问题背后可能有两个原因。应用程序中的其中一个Pod可能正在使用CommonCrypto,或者Swift语言版本可能不明确。对于这两个问题,都有以下解决方案:
方法1
如果没有该Pod,也许您可以尝试使用与项目中可能遇到的一些旧Pod相同的步骤。
添加的信息:另外,如果Pod内发生代码错误,则首先需要解决该代码问题,然后尝试再次编译项目。
方法2
请确保您的项目Swift语言版本是正确的版本。对于Xcode 10,我建议您使用Swift 4.2,也可以选择当前编写代码的版本。 Your can follow your Build Settings in your target as in the this image
我希望这会有所帮助
致谢
答案 1 :(得分:0)
也许将来有人会在解析json排序时犯我的错误,如下所示:
let countryList = try? JSONDecoder().decode([Country].self, from: data)
if let countryList = countryList {
completion(countryList.sorted(by: <))
}