【问题标题】:command failed due to signal: Segmentation fault: 11?由于信号,命令失败:分段错误:11?
【发布时间】:2015-12-16 04:26:36
【问题描述】:

我收到了command failed due to signal: Segmentation fault: 11? 错误,但它对我来说非常模棱两可,为什么?它确实在调试器中提供了以下响应,但指向以下代码:

1.  While type-checking 'textFieldShouldEndEditing' at /Users/macbookair1/Documents/programming/MyApp/MyApp/SignUpViewController.swift:224:5
2.  While type-checking expression at [/Users/macbookair1/Documents/programming/MyApp/MyApp/SignUpViewController.swift:231:9 - line:252:11] RangeText="query.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]?, error: NSError?) in
            if error == nil {
                if (objects!.count > 0){


                    if (UIApplication.sharedApplication().delegate as! AppDelegate).signUpOn {
                    let myAlert = SCLAlertView().showError("Woah There", subTitle: "username \(textField.text!) is already taken", closeButtonTitle: "Got It")
                    myAlert.alertview.contentView.backgroundColor = UIColor(red:1.0, green:0.18, blue:0.18, alpha:1.0)
                    myAlert.alertview.circleBG.backgroundColor = UIColor(red:1.0, green:0.18, blue:0.18, alpha:1.0)
                    myAlert.alertview.labelTitle.textColor = UIColor.whiteColor()
                    myAlert.alertview.contentView.layer.borderColor = UIColor(red:1.0, green:0.18, blue:0.18, alpha:1.0).CGColor
                    myAlert.alertview.viewText.textColor = UIColor.whiteColor()
                    myAlert.alertview.viewText.backgroundColor = UIColor(red:1.0, green:0.18, blue:0.18, alpha:1.0)
                    }
                } else {
                    print("Username is available.")
                }
            } else {
                print("error")
            }
          }"

另一个指向此代码:

1.  While type-checking 'loadBooks' at /Users/macbookair1/Documents/programming/MyApp/MyApp/ThirdCollectionViewController.swift:103:5
2.  While type-checking expression at [/Users/macbookair1/Documents/programming/MyApp/MyApp/ThirdCollectionViewController.swift:108:9 - line:127:9] RangeText="query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
            if error == nil {
                self.books.removeAll()
                let bookObjects = objects as! [PFObject]
                for (_, object) in bookObjects.enumerate() {
                    self.books.append(Book(pfBook: object))
                }
            }else if let secondMessage = error?.userInfo["error"] as? String
                where secondMessage == "The Internet connection appears to be offline." {
                    self.failedMessage(secondMessage)
                    self.activityIndicator.hidden = true
                    self.activityIndicator.stopAnimating()
            }
            dispatch_async(dispatch_get_main_queue()){

                self.collectionView!.reloadData()
                self.refreshControl.endRefreshing()
                self.activityIndicator.stopAnimating()
            }
        }"

如何摆脱这个错误?

【问题讨论】:

    标签: ios xcode swift error-handling


    【解决方案1】:

    这是 LLVM 本身在编译 swift 时可能发生的一种错误。 尝试使用替代表达式或使用较新版本的 swift(如撰写本文时的 2.0),我遇到过这种情况,某些时候表达式只会导致崩溃,拆分分配甚至使用 Objective-c 都不会导致崩溃.

    【讨论】:

    • 我相信这与我的两个代码块的"query.findObjectsInBackgroundWithBlock 声明有关
    • 它可以在完全有效的代码行上出错。尝试简化并分解为多个部分。例如,一旦尝试创建两个组件的 URL 时它会崩溃,我必须创建一个字符串,然后创建另一个字符串,然后它就起作用了。
    • 那么查看错误中的第一个代码,我应该如何正确分解它?
    • 很难说,因为它在整个块上崩溃,尝试将块移动到自己的定义中作为变量来分隔它
    猜你喜欢
    • 2014-12-20
    • 1970-01-01
    • 2017-06-23
    • 2017-03-21
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多