xcode Swift:从 iOS 7 编译存档时出现分段错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26731198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift: segmentation fault when compiling for Archive from iOS 7
提问by FrCr
I've always had this issue so I started creating a new single-view application, in Swift, for both iPhone and iPad. When the target is iOS 8.1 everything works fine, but if I set iOS 7.1 (or 7), i get a Segmentation fault. This happens when i go to Product > Archive, when i Run the project in the simulator or my device, everything is fine. I tried with both iOS 7 and 8 simulators and it compiles. As I said, the problem is not in the code since it behaves this way even with a newly created project.
我一直有这个问题,所以我开始在 Swift 中为 iPhone 和 iPad 创建一个新的单视图应用程序。当目标是 iOS 8.1 时,一切正常,但如果我设置 iOS 7.1(或 7),则会出现分段错误。当我转到“产品”>“存档”时会发生这种情况,当我在模拟器或我的设备中运行该项目时,一切正常。我尝试了 iOS 7 和 8 模拟器并且它编译了。正如我所说,问题不在代码中,因为即使是新创建的项目,它也会以这种方式运行。
CompileSwift normal armv7 /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift
cd /Users/francesco/Documents/XCode Projects/Prova
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file "/Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift" "/Users/francesco/Documents/XCode Projects/Prova/Prova/AppDelegate.swift" -target armv7-apple-ios7.1 -target-cpu cortex-a8 -target-abi apcs-gnu -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -F /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -g -module-cache-path /Users/francesco/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-generated-files.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-own-target-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-all-target-headers.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-project-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources/armv7 -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources -emit-module-doc-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftdoc -O -module-name Prova -emit-module-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.dia -emit-dependencies-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.d -o /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.o
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift /Users/francesco/Documents/XCode Projects/Prova/Prova/AppDelegate.swift -target armv7-apple-ios7.1 -target-cpu cortex-a8 -target-abi apcs-gnu -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -F /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -g -module-cache-path /Users/francesco/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-generated-files.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-own-target-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-all-target-headers.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-project-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources/armv7 -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources -emit-module-doc-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftdoc -O -module-name Prova -emit-module-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.dia -emit-dependencies-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.d -o /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.o
1. While type-checking 'ViewController' at /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift:11:1
Command failed due to signal: Segmentation fault: 11
Does anybody have any idea about this issue?
有没有人对这个问题有任何想法?
UPDATE: I can target armv7s and arm64 to iOS 7, armv7 is what causes the issue; if armv7 is targeted to iOS 8 and others to iOS 7, everything works. That's not a good solution since it's more important to support older OSs on older devices, in my opinion.
更新:我可以将 armv7s 和 arm64 定位到 iOS 7,armv7 是导致问题的原因;如果 armv7 针对 iOS 8 而其他针对 iOS 7,则一切正常。在我看来,这不是一个好的解决方案,因为在旧设备上支持旧操作系统更为重要。
采纳答案by FrCr
Closing Xcode and opening another project, then loading back this one, solved the issue. It was a bug, I guess.
关闭Xcode并打开另一个项目,然后重新加载这个项目,解决了这个问题。这是一个错误,我猜。
回答by Hannes
I had the same problem until someone told me that it's a problem with the certificates. Go to the Dev Center and regenerate your Certificates & Provisioning Profiles. After that it should work!
我遇到了同样的问题,直到有人告诉我这是证书的问题。转到开发中心并重新生成您的证书和供应配置文件。之后它应该工作!
回答by stackguy
I had the same issue on Xcode 6.1. Building and running the Swift project was no problem, archiving led to an error:
我在 Xcode 6.1 上遇到了同样的问题。构建和运行 Swift 项目没有问题,归档导致错误:
Command failed due to signal: Segmentation fault: 11
1. While type-checking <my Swift class>
Changing the project's Deployment Target from 7.0
to 7.1
solved the problem, the app can now be archived.
更改项目的部署目标7.0
以7.1
解决问题,现在可以存档应用程序。
回答by LNI
I ran into the same issue, and trying the selected answer (i.e. closing and re-opening Xcode etc) as well as other experiments did not help. Based on the stack trace the following code was failing:
我遇到了同样的问题,尝试选择的答案(即关闭和重新打开 Xcode 等)以及其他实验都没有帮助。根据堆栈跟踪,以下代码失败:
var cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: 0)) as UITableViewCell
var cell2 = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row2, inSection: 0)) as UITableViewCell
In subsequent code I was treating both cell and cell2 as optionals, so I did not bother unwrapping these assignments. Apparently Swift hated it enough to Seg-fault on me. After some experimentation I changed the code to
在随后的代码中,我将 cell 和 cell2 都视为可选项,因此我没有费心解开这些分配。显然,斯威夫特非常讨厌它对我进行 Seg-fault。经过一些实验,我将代码更改为
var cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: 0)) as UITableViewCell!
var cell2 = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row2, inSection: 0)) as UITableViewCell!
and the Swift Segmentation fault stopped. The issue was with Xcode 6.1.1 (6A2008A).
并且 Swift Segmentation 错误停止了。问题出在 Xcode 6.1.1 (6A2008A) 上。
If you are still having this issue you should look at where the stack trace mentions the crash is occurring. It will say something about emitting code and should be locatable.
如果您仍然遇到此问题,您应该查看堆栈跟踪中提到发生崩溃的位置。它会说一些关于发出代码的信息,并且应该是可定位的。
回答by rob
I had the same problem – compilation would run fine in the simulator and on the device, but I would get seg fault 11
during archiving. I tried some of the other solutions here but was still getting the error.
我遇到了同样的问题——编译会在模拟器和设备上正常运行,但我会seg fault 11
在存档过程中遇到问题。我在这里尝试了其他一些解决方案,但仍然出现错误。
I isolated the cause to a method that used generics and the NSCoding protocol. Removing the protocol fixed the problem.
我将原因与使用泛型和 NSCoding 协议的方法隔离开来。删除协议解决了问题。
This was causing the seg fault:
这导致了段错误:
func saveToDefaults<T: NSCoding>(objectToSave : T?, key : String)
But changing it to this fixed it:
但是将其更改为此修复了它:
func saveToDefaults<T>(objectToSave : T?, key : String){
if let objectToSave = objectToSave as? NSCoding {
...
It's not as robust as the original, but it compiles.
它不像原来的那么健壮,但它可以编译。