Swift:从iOS 7编译Archive时出现分段错误

时间:2014-11-04 09:05:11

标签: ios iphone xcode swift fault

我一直有这个问题所以我开始在Swift中为iPhone和iPad创建一个新的单视图应用程序。 当目标是iOS 8.1时,一切正常,但如果我设置iOS 7.1(或7),我会收到Segmentation故障。当我转到Product>时会发生这种情况。存档,当我在模拟器或我的设备中运行项目时,一切都很好。我尝试使用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

有人对这个问题有任何想法吗?

更新:我可以将armv7s和arm64定位到iOS 7,armv7是导致问题的原因;如果armv7针对iOS 8而其他人针对iOS 7,那么一切正常。这不是一个好的解决方案,因为在我看来,在旧设备上支持旧的操作系统更为重要。

5 个答案:

答案 0 :(得分:3)

我有同样的问题,直到有人告诉我这是证书的问题。转到开发人员中心并重新生成您的证书&供应配置文件。之后它应该工作!

答案 1 :(得分:2)

关闭Xcode并打开另一个项目,然后加载回来,解决了这个问题。 我想这是一个错误。

答案 2 :(得分:2)

我在Xcode 6.1上遇到了同样的问题。构建和运行Swift项目没问题,归档导致错误:

Command failed due to signal: Segmentation fault: 11
1.  While type-checking <my Swift class>

将项目的部署目标从7.0更改为7.1解决了问题,现在可以存档该应用。

答案 3 :(得分:0)

我遇到了同样的问题,尝试选择的答案(即关闭并重新打开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

在后续代码中,我将cell和cell2都视为选项,所以我没有打扰解开这些赋值。很显然,斯威夫特非常讨厌我的段错。经过一些实验,我将代码更改为

var cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: 0)) as UITableViewCell!
var cell2 = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row2, inSection: 0)) as UITableViewCell!

并且Swift Segmentation故障停止了。问题出在Xcode 6.1.1(6A2008A)上。

如果您仍然遇到此问题,您应该查看堆栈跟踪提到崩溃发生的位置。它会说一些关于发出代码的东西,应该是可以定位的。

答案 4 :(得分:0)

我有同样的问题 - 编译在模拟器和设备上运行良好,但在归档期间我会得到seg fault 11。我在这里尝试了其他一些解决方案,但仍然遇到错误。

我将原因分离为使用泛型和NSCoding协议的方法。删除协议解决了问题。

这导致了seg错误:

 func saveToDefaults<T: NSCoding>(objectToSave : T?, key : String)

但是将其更改为固定它:

 func saveToDefaults<T>(objectToSave : T?, key : String){
     if let objectToSave = objectToSave as? NSCoding {
          ...

它不像原版那样强大,但它会编译。