命令因信号:段错误:11而失败

158

当尝试编译我的Swift应用程序时,我遇到了错误...

由于信号:Segmentation fault: 11,命令失败

我正在使用Xcode 6.1,尝试为运行在iOS 8.1上的iPhone 5构建。

我的代码

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var username: UITextField!
    @IBAction func signIn(sender: AnyObject) {

        PFUser.logInWithUsernameInBackground(username.text, password:"mypass") {
            (user: PFUser!, error: NSError!) -> Void in
            if user != nil {
                println("Logged In")
            } else {

                func myMethod() {
                    var user = PFUser()
                    user.username = username.text
                    user.password = " "
                    user.signUpInBackgroundWithBlock {
                        (succeeded: Bool!, error: NSError!) -> Void in
                        if error == nil {
                            // Hooray! Let them use the app now.
                        } else {
                                println("Signed Up")
                        }
                    }
                }

             println(error)
            }
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        Parse.setApplicationId("key here")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

还有错误文本!

CompileSwift normal arm64 /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift
    cd /Users/Alec/Desktop/Re-Chat/Re-Chat
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/AppDelegate.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat -g -import-objc-header /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/Re-Chat-Bridging-Header.h -module-cache-path /Users/Alec/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-generated-files.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-own-target-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-all-target-headers.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-project-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources/arm64 -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name Re_Chat -emit-module-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.d -o /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.o
0  swift                    0x0000000108145a68 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x0000000108145f54 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff86631f1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fd0ac1eb010 _sigtramp + 633049360
4  swift                    0x00000001075d4517 swift::Lowering::SILGenFunction::emitClosureValue(swift::SILLocation, swift::SILDeclRef, llvm::ArrayRef<swift::Substitution>, swift::AnyFunctionRef) + 1303
5  swift                    0x00000001075c599e swift::Lowering::SILGenFunction::visitFuncDecl(swift::FuncDecl*) + 190
6  swift                    0x000000010760987c swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 380
7  swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
8  swift                    0x000000010760a0a5 swift::Lowering::SILGenFunction::visitIfStmt(swift::IfStmt*) + 757
9  swift                    0x000000010760c8f6 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 166
10 swift                    0x00000001076097e8 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 232
11 swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
12 swift                    0x00000001075d52dd swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 205
13 swift                    0x00000001075b4234 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 196
14 swift                    0x00000001075eef71 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 97
15 swift                    0x00000001075e1866 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 2870
16 swift                    0x00000001075e24da swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 6058
17 swift                    0x00000001075cfa0b swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 235
18 swift                    0x00000001075ae824 swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&) && + 196
19 swift                    0x0000000107604a69 swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::SILType) && + 233
20 swift                    0x00000001075f371c swift::Lowering::SILGenFunction::emitInjectOptionalValueInto(swift::SILLocation, swift::Lowering::RValueSource&&, swift::SILValue, swift::Lowering::TypeLowering const&) + 268
21 swift                    0x00000001075e9b8d swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 36445
22 swift                    0x00000001075e3e2b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 12539
23 swift                    0x00000001075e202b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 4859
24 swift                    0x00000001075cfab6 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 22
25 swift                    0x00000001075bffc4 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::RValueSource&&, swift::Lowering::AbstractionPattern) + 836
26 swift                    0x00000001075bf582 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::RValueSource&&, swift::Lowering::AbstractionPattern) + 98
27 swift                    0x00000001075b7ff8 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1128
28 swift                    0x00000001075b751a swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 58
29 swift                    0x00000001075e0d81 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 81
30 swift                    0x00000001075ea00d swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 237
31 swift                    0x0000000107609829 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 297
32 swift                    0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 152
33 swift                    0x00000001075d4ee0 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 256
34 swift                    0x00000001075b3659 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 233
35 swift                    0x00000001075cea93 swift::ASTVisitor<SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 355
36 swift                    0x00000001075cd7eb SILGenType::emitType() + 203
37 swift                    0x00000001075c85ae swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 30
38 swift                    0x00000001075b555b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 395
39 swift                    0x00000001075b581a swift::SILModule::constructSIL(swift::Module*, swift::SourceFile*, swift::Optional<unsigned int>) + 314
40 swift                    0x00000001075b5968 swift::performSILGeneration(swift::SourceFile&, swift::Optional<unsigned int>) + 72
41 swift                    0x000000010748be18 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 3432
42 swift                    0x000000010748996d main + 1677
43 libdyld.dylib            0x00007fff8aa4c5c9 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/AppDelegate.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat -g -import-objc-header /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/Re-Chat-Bridging-Header.h -module-cache-path /Users/Alec/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-generated-files.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-own-target-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-all-target-headers.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-project-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources/arm64 -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name Re_Chat -emit-module-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.d -o /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.o 
1.  While emitting SIL for 'signIn' at /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift:14:15
2.  While silgen closureexpr SIL function @_TFFC7Re_Chat14ViewController6signInFS0_FPSs9AnyObject_T_U_FTGSQCSo6PFUser_GSQCSo7NSError__T_ for expression at [/Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift:16:80 - line:45:9] RangeText="{
            (user: PFUser!, error: NSError!) -> Void in
            if user != nil {
                // Do stuff after successful login.

                println("Logged In")
            } else {

                func myMethod() {
                    var user = PFUser()
                    user.username = username.text
                    user.password = ""
                    // other fields can be set just like with PFObject


                    user.signUpInBackgroundWithBlock {
                        (succeeded: Bool!, error: NSError!) -> Void in
                        if error == nil {
                            // Hooray! Let them use the app now.
                        } else {
                                println("Signed Up")
                        }
                    }
                }


             println("error")
            }
        }"

显示错误的代码和您发布的代码不同。您的代码是用于登录的,而错误代码是注册方法。您是否设置了闭包中断点以尝试识别问题? - Paulw11
你不需要猜测。在项目所在的终端中键入 xcodebuild -verbose,并查看错误的具体位置和原因。 - oyalhi
57个回答

94

当编译器在您的代码中感到困惑时,就会出现此错误。我注意到您有许多似乎嵌套在其他函数中的函数。您可以尝试逐步注释其中一些内容,以查看错误是否消失。这样,您就可以确定问题所在。您不能使用断点,因为这是一个编译时错误,而不是运行时错误。


1
谢谢,但最终发现与架构有关。很奇怪,是吧? - Alec.
3
ParanoidAndroid,请您详细说明问题是什么?我也遇到了这个问题。 - Alex
我因为没有指定可选参数(第二个参数)而出现了问题,似乎是它前面的三元运算符让Xcode 6.3感到困惑addPointforTeamAtPosition(command == extensionCommandTeam1Point ? 0 : 1, pointKind: .Regular) - Rivera
@Rivera,你说得对。同样的问题也出现在这里:updateAnswerCount(++numAttempts == 1 ? &hitCount : &missCount),将其拆分成常规的if-else语句解决了这个问题。 - Kevin Owens
如果您定义了模糊的初始化程序,则当前的Xcode beta会出现此错误。我注意到这种情况最常见的是当我设置默认参数值时,一个使用默认(排除)参数的初始化程序变得更难与同一类的另一个初始化程序区分开来。可能有很多原因导致这种情况发生,但错误日志通常会给出一些线索以找到真正的问题所在位置,只是这不是一个非常有用的错误,所以需要在有机会时向Apple报告。 - Haravikk
显示剩余6条评论

51

我最近遇到了同样的问题,我会试着总结一下我是如何解决它的,因为很多答案都过于特定,不能帮助每个人。

1. 首先查看错误信息底部,确定引起分段错误的文件和函数。

Error message

2. 然后我查看该函数并注释掉所有内容。我编译后它现在可以工作了。然后我逐步取消函数的注释,直到找到引起错误的那行代码。之后我就能够修复它并使其正常工作。:)


2
最后几行提供了最好的提示。这个答案帮了很多! - AppreciateIt
1
这应该是被接受的答案。分段错误的原因可能会有所不同,这是正确的诊断方法。 - Juan Carlos Ospina Gonzalez

43

对于其他遇到此问题的人...我发现问题是由于导入自定义框架引起的,我不知道如何纠正它。但是只需删除导入以及任何引用框架中项目的代码即可解决问题。

(╯°□°)╯︵ ┻━┻

希望这可以为某些人节省几个小时追踪导致问题的代码行。


1
我在Xcode 7中遇到了同样的问题。问题实际上是我添加到Swift文件中的几行代码。这些行从第三方库中使用了一个组件。在我的情况下,它是Eureka。一旦我删除了我添加的这些行,它就可以完美地构建了。 - Asanga Dewaguru
我删除了一个协议,但仍有一些类在使用它。XCode应该将它们标出来,但在我的情况下没有。谢谢。 - harsh_v
3
在我更新到Xcode 7.3时,我的情况也是这样,当时我进行了Eureka更新到v1.5版本并执行了pod install,最终一切都正常了。 - Lyck
1
更新pod并重新安装库对我很有帮助,谢谢你的回答。 - Kamal Upasena
1
我也遇到了Eureka的问题,现在版本是(5.0.0)。 - agandi
显示剩余3条评论

16

对我来说,这是由于Swift 2.0中Parse SDK语法的更改引起的。如果您正在使用Parse并升级到Swift 2.0,则以下语法将发生更改:

Swift 1.2:


myPFQuery.findObjectsInBackgroundWithBlock({ (queryResults: [AnyObject]?, error: NSError?) -> Void in

    // CODE

})

Swift 2.0:


Swift 2.0:
myPFQuery.findObjectsInBackgroundWithBlock { (queryResults: [PFObject]?, error: NSError?) -> Void in

    // CODE

}

去除第一个'('和最后一个')'是导致最大问题的原因。花费了我很长时间才发现这个问题!


这绝对是罪魁祸首,但是你的代码行并没有为我解决问题。有任何新的细节吗? - Lucas Azzopardi
你确定你已经找到并更改了所有实例吗?此外,我相信以下调用也已更改(删除第一个和最后一个括号,因此代码应该读作以下内容)...pfObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in //code } - AT3D
运行良好 - SARATH SASI
所以尾随闭包语法也造成了这个问题? - Beltalowda

9

我遇到了这个错误。经过一些挫折,我尝试了Xcode清理,然后一切都开始正常工作了。我在此留下记录,以备将来参考。


7
object.doubleValue = dict["doublevalue"] as! Int

我回退了每一步操作,之后找到了原因......将Double变量强制转换为Int类型。

1
在我的情况下,我在将Int强制转换为String变量时出现了错误。 - Ian Pinto
好的,但是这样不会给你编译错误吗?!! - SoliQuiD
因此,在堆栈跟踪中报告的错误与我的情况无关,也不涉及强制转换。 - Ian Pinto

7
当我在从Swift转换为Swift 2.0时遇到此错误时,它明确指出了一个特定的文件(blahClass.swift)存在问题,并在错误消息文本中概述了所有警告和错误。 我手动解决了这些问题,现在应用程序可以编译成功。

3
在这里添加另一个数据点。我在进行Swift 2迁移时也遇到了这个错误。最终我打开了它失败的文件,并注释掉大部分的代码。然后应用程序编译成功,我能够逐行取消注释代码以追踪问题。 - Chad Pavliska

7

这对我来说是由于我的代码引起的。在XCode中详细的编译器输出实际上可以确定崩溃的方法。

然后我注释了该方法中的所有代码,使其返回nil,它确实编译通过了。然后我使用不同和更简单的代码重新实现了该方法,它就可以工作了。

我向Apple提交了一个错误报告。这就是在XCode 7 / Swift 2.0中导致崩溃的-尽管有些疯狂的-代码。

  func numberAndTitleFromDirectoryName(dirName: String) -> (Int, String)? {
    let components = dirName.characters.split(maxSplit: 1, allowEmptySlices: false) { $0 == " " }.map { String($0) }.map { String($0) }
    if let number = components.first?.toInt() {
        if let title = components.last {
            return (number, title)
        }
    }
    return nil;
  }

我想我在使用map函数时有些过于兴奋了...新版本更简单,也更易于理解。尽管如此,编译器不应该崩溃。最坏的情况下,它应该显示一些错误。这段代码在Swift 1.x中可以工作。


4

如果使用git,则很容易解决。

1) 在终端中:

git stash

2) Segmentation fault 错误消失。

3) 运行应用程序。

4) 在终端中输入:

git stash pop

5) Xcode现在告诉您真正的问题。


1
嘿,朋友!非常感谢你。你帮我省去了很多麻烦和时间! - stefat

4
我在使用Xcode 7.3和iOS 9.3时也遇到了类似的问题。 由于信号错误,命令失败: 分段错误: 11

屏幕截图

常规步骤,如清理(cmd+shift+k)代码、删除派生数据和退出Xcode都没有用。

我的代码中有一些问题。

原因是 [txtUserName.text.characters.count = 0]

在你的情况下,请检查你的代码并修复问题。


15
提醒自己,如果你的代码出现问题,遵循以上有用提示“审查您的代码并修复罪犯”,谁知道会有帮助…… - Stu P.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接