【问题标题】:Command failed due to signal: Segmentation fault: 11由于信号,命令失败:分段错误:11
【发布时间】:2014-12-20 20:41:11
【问题描述】:

我收到了错误...

由于信号而导致命令失败:分段错误:11

... 尝试编译我的 Swift 应用程序时。我正在使用 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")
            }
        }"

【问题讨论】:

  • 报错中显示的代码和你发布的代码不一样。您的代码用于登录,错误代码是注册方法。您是否在闭包中设置了断点来尝试识别问题?
  • 您无需猜测。从您的项目所在的终端输入xcodebuild -verbose,并查看究竟是什么错误,它在哪里等等。

标签: ios swift segmentation-fault


【解决方案1】:

当您的开发目标不支持任何 UIControl 时

就我而言,我在一个开发目标为8.0 的项目中使用StackView。 如果您的开发目标不支持任何 UIControl,则可能会发生此错误。

当您设置错误的目标时

如果您在下面的行中保留默认目标“目标”而不是自身,则会发生分段错误 11。

shareBtn.addTarget(self, action: #selector(ViewController.share(_:)), for: .touchUpInside)

【讨论】:

    【解决方案2】:

    我的代码中有这一行

    weakSelf?.notifications = weakSelf?.notifications ?? [] + weakSelf?.chatNotificationDataSource ?? []
    

    这会导致分段错误。 但后来我用这种方式改变了它:

    weakSelf?.notifications = (weakSelf?.notifications ?? []) + (weakSelf?.chatNotificationDataSource ?? [])
    

    应用开始工作。

    【讨论】:

      【解决方案3】:

      我还遇到了Segmentation fault: 11 error,因为我正在调用一个返回Any object 的方法,编译器对理解正在使用的对象类型感到困惑。

      Any object 转换为我正在使用的所需类型,解决了我的问题。

      【讨论】:

        【解决方案4】:

        如果您使用多个版本的 XCode,如果您的路径已更改(例如,您将 DMG 下载到桌面,解压缩,但随后将 XCode 移动到应用程序),则很容易发生此错误。仔细阅读 XCode 中给出的 Segmentation Fault 11 错误,它可能引用了导致 Segmentation Fault 的旧路径。如果是这样,您可以通过以下任一方式修复它:

        1. xcode-选择正确的路径。例如。 sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer/ (这里显然输入你的正确路径)
        2. 安装第二个版本的 XCode 时,请确保将其解压缩到最终路径(解压缩到应用程序本身),并且这样做时“XCode.app”不存在(如果存在,请重命名您的前一个) .安装后,您可以根据需要重命名。

        此问题的另一个潜在解决方法:

        从 El Capitan 升级到 Sierra 并在此升级后启动 Xcode 时“安装额外组件”在第一次发生这种情况时为我解决了这个问题。

        【讨论】:

          【解决方案5】:

          在从 Swift 2.0 移植到 1.2 时,我实际上有点搞砸了 Core Data 实体(不要问为什么) 我删除了所有实体类并重新创建了它们。然后我收到了很多错误消息,当我修复它们时,所有项目都成功构建。

          【讨论】:

            【解决方案6】:

            请注意那些可能与我处于相同情况的人,因为这花了我很多时间来解决......

            我在 Xcode 中使用 Find/Replace 功能后遇到了这个错误。问题是由于我的粗心,某些字符被“过度替换”(即不仅替换了相关部分,还替换了冗余部分),因此一些变量变成了未定义的变量。尽管如此,那些未定义的变量并没有在编译中被捕获(即使在发出clean 之后),最终信号分段错误显示在屏幕上。

            【讨论】:

              【解决方案7】:

              在 Command failed due to signal: Segmentation fault: 11 之后会提到一个文件名。至少在我的情况下是这样。随着 Swift 升级到 2.0,一些核心属性被更改为 optional。如果没有适当地处理它,它就会引发该错误。处理好可选选项消除了错误。就我而言,这是由于未处理:

                      if let scheduledNotifications = UIApplication.sharedApplication().scheduledLocalNotifications as [UILocalNotification]?{
              }  
              

              祝你好运!

              【讨论】:

                【解决方案8】:

                我在构建测试时遇到了这个问题。构建运行工作正常。 Xcode 7/Swift 2 不喜欢变量的初始化方式。此代码在 Xcode 6.4 中运行良好。这是导致段错误的行:

                var lineWidth: CGFloat = (UIScreen.mainScreen().scale == 1.0) ? 1.0 : 0.5
                

                改成这样就解决了问题:

                var lineWidth: CGFloat {
                    return (UIScreen.mainScreen().scale == 1.0) ? 1.0 : 0.5
                }
                

                【讨论】:

                  【解决方案9】:

                  let 属性中数组中的命名元组给了我段错误问题。

                  【讨论】:

                    【解决方案10】:

                    当我的代码中有一些嵌套函数并且 其中一个嵌套函数正在调用另一个嵌套函数。

                    我刚刚删除了嵌套函数之间的链接,此问题已得到修复。

                    感谢@Ron B 的回答。

                    【讨论】:

                      【解决方案11】:

                      我刚遇到这个问题,发现这是因为我不小心在一个函数上留下了override,我从类移到了协议(因此子类不再覆盖父类的函数) .

                      【讨论】:

                        【解决方案12】:

                        我在尝试在 Swift 2 中定义新的 OptionSetType 结构时遇到了这个错误。当我将 init() 参数上的类型从 Self.RawValue 更正为 Int 时,崩溃停止发生:

                        // bad:
                        //  public init(rawValue: Self.RawValue) {
                        //      self.rawValue = rawValue
                        //  }
                        
                        // good:
                        public init(rawValue: Int) {
                            self.rawValue = rawValue
                        }
                        

                        【讨论】:

                          【解决方案13】:

                          在我的例子中,我有几个方法实例使用这样的签名进行闭包(注意 optional 字典数组):

                          // 'results' being nil means "failure".
                          func queryItems(
                              completion:( (results:[[String:AnyObject]]?)->(Void) )
                              )
                          {
                             // (async operation...)
                          

                          ...我开始重构为:

                          // 'results' is NEVER nil (at most, empty). Pass any errors to the 
                          //   failure: closure instead.
                          func queryItems(
                              success:( (results:[[String:AnyObject]])->(Void) ),
                              failure:( (error:NSError) -> (Void) )
                              )
                          {
                             // (async operation...)
                          

                          ...但没有完成,所以一些方法期望一个带有可选参数的闭包,并且在哪里传递一个非可选参数(反之亦然?),我猜编译器迷失了方向。

                          【讨论】:

                            【解决方案14】:

                            对我来说,当我不小心在从类 init 方法调用的方法的 completionHandler 中调用了“super.init()”时,就会出现这种情况。

                            init() {        
                                    someFunction(argument, completionHandler: { (data) -> () in
                                        super.init()
                            ...
                            }
                            

                            而不是

                            init() {    
                                    super.init()
                                    someFunction(argument, completionHandler: { (data) -> () in
                                    ...
                            }
                            

                            【讨论】:

                              【解决方案15】:

                              在我的情况下 Product Clean 然后重新启动 Xcode 确实解决了这个问题...

                              【讨论】:

                                【解决方案16】:

                                我在第一次使用Realm.io 时遇到了同样的问题。错误的原因是我将目标命名为Realm,这导致了命名空间冲突。如this issue 所述,在我将项目和目标名称更改为其他名称后,该问题已得到解决。

                                我的建议是检查类似的命名空间冲突。

                                【讨论】:

                                  【解决方案17】:

                                  从 NSUserDefaults 获取值时出现此错误。以下给出错误:

                                  let arr = defaults.objectForKey("myArray")
                                  

                                  修复错误的方法是将类型转换为存储在 NSUserDefaults 中的正确类型。以下没有错误:

                                  let arr = defaults.objectForKey("myArray") as! Array<String>
                                  

                                  【讨论】:

                                    【解决方案18】:

                                    这是一个简单的解决方案

                                    只需按 cmd+shift+k

                                    清理项目解决了我的问题

                                    【讨论】:

                                      【解决方案19】:

                                      在我的例子中,我试图用一个可以在其所有子类上工作的辅助方法来扩展一个 CoreData 类:

                                      extension ExampleCoreDataClass {
                                         static func insert() -> Self {
                                         ...
                                      

                                      我没有收到任何警告,但是当我尝试编译它时,出现了分段错误。

                                      经过一段时间的努力,我改用了协议扩展,这解决了错误:

                                      extension NSFetchRequestResult where Self: ExampleCoreDataClass {
                                         static func insert() -> Self {
                                         ...
                                      

                                      【讨论】:

                                        【解决方案20】:

                                        当我尝试从单例中的“静态范围”访问单例结构实例的属性时出现此错误(该范围内包含从未实例化的枚举常量)

                                        【讨论】:

                                          【解决方案21】:

                                          就我而言,我忘记在源代码中删除“colorLiteral”(未分配给任何属性或未作为方法参数传递),这就是编译器无法编译所有 swift 文件的原因。我刚刚删除了“colorLiteral”,它的工作正常。

                                          【讨论】:

                                            【解决方案22】:

                                            对我来说,这是因为传递 [String : Int] 而不是 [String : Any]

                                            【讨论】:

                                              【解决方案23】:

                                              我试图在我的代码中寻找所有答案,相同的 repo 已成功构建在其他开发人员的 PC 中。但不是在我的:(

                                              我花了将近一周的时间来修复它。我做了所有可能的检查组合,比如删除派生数据、关闭 xcode、重启电脑、git stash、重置它们都没有帮助。 然后我复制了在 Xcode 中失败的构建命令并在终端中运行它。 它失败了。又显示了一行

                                              (end of response file)
                                              clang: error: unable to execute command: Segmentation fault: 11
                                              clang: error: linker command failed due to signal (use -v to see invocation)
                                              

                                              构建命令超过 76K 个字符 所以我删除了一些非强制性的参数,并且能够在终端中进一步进行。

                                              所以我为解决这个问题所做的就是从 ~/Desktop/Work/PROJECT_NAME/repo/ssh/AAA~/Desktop/repo/ 问题解决了

                                              长话短说,将回购靠近 ~/ 如果您像我一样面对这种情况,路径会变得更少。 我的 Xcode 12.3 版

                                              【讨论】:

                                                【解决方案24】:

                                                在我的例子中,IGListKit 将名为 IGListSectionController 的类重构为 ListSectionController,而我已经有了一个名为 ListSectionController 的类。我使用了查找和替换,但不知道我有一个同名的类。

                                                class ListSectionController : ListSectionController

                                                我完整阅读了错误消息并得出结论,当您有循环依赖项时也会发生此错误。这在任何 cmet 中都没有提到,我希望这会有所帮助。

                                                【讨论】:

                                                  【解决方案25】:

                                                  我遇到了完全相同的问题,经过数小时的调试后,我发现这是因为我使用 .subscript() 而不是 [] 之间访问下标。 XCode 认为这是完全有效的,但在构建时会出现此分段错误错误。

                                                  【讨论】:

                                                    【解决方案26】:

                                                    发现在 WKInterfaceController(即 Watch 应用)中使用三元语句时会发生这种情况!

                                                    【讨论】:

                                                      【解决方案27】:

                                                      我在 CI 构建中遇到了这个错误,我无法在本地重现它。原来我使用的 Xcode 版本与我的 CI 使用的不同。

                                                      【讨论】:

                                                        猜你喜欢
                                                        • 2015-12-16
                                                        • 1970-01-01
                                                        • 2017-06-23
                                                        • 2017-03-21
                                                        • 2016-11-23
                                                        • 1970-01-01
                                                        • 1970-01-01
                                                        • 1970-01-01
                                                        • 1970-01-01
                                                        相关资源
                                                        最近更新 更多