简体   繁体   中英

I keep getting “signal 1: SIGABRT” in swift 3 and I don't know how to get around it

I've checked all of my connections and NONE of them are broken. I've reconnected all of them and checked everything but I keep getting this error. It comes in the first line of the App Delegate and I don't know why. Here's the code.

class DetailsViewController: UIViewController, SFSafariViewControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate{

    let imagePicker = UIImagePickerController()


    @IBOutlet weak var MITImageView: UIImageView!
    @IBOutlet weak var StanfordImageView: UIImageView!
    @IBOutlet weak var HarvardImageView: UIImageView!

    @IBAction func MITSafariViewControllerButton(_ sender: UIButton) {
        let url = NSURL(string: MITUrl)!
        let svc = SFSafariViewController(url: url as URL)
        present(svc, animated: true, completion: nil)
    }

    @IBAction func StanfordSafariViewControllerButton(_ sender: UIButton) {
        let url = NSURL(string: StanfordUrl)!
        let svc = SFSafariViewController(url: url as URL)
        present(svc, animated: true, completion: nil)
    }

    @IBAction func HarvardSafariViewControllerButton(_ sender: UIButton) {
        let url = NSURL(string: HarvardUrl)!
        let svc = SFSafariViewController(url: url as URL)
        present(svc, animated: true, completion: nil)

    }

    @IBAction func imageChangeButton(_ sender: UIButton) {
        imagePickerClass().imagePickerControllerMIT(picker: imagePicker)
    }
    @IBAction func imageChangeButtonStanford(_ sender: UIButton) {
        imagePickerClass().imagePickerControllerStanford(picker: imagePicker)
    }

    @IBAction func imageChangeButtonHarvard(_ sender: UIButton) {
        imagePickerClass().imagePickerControllerHarvard(picker: imagePicker)
    }

    var MITUrl = "http://web.mit.edu"
    var StanfordUrl = "http://stanford.edu"
    var HarvardUrl = "http://www.harvard.edu"
    override func viewDidLoad() {
        super.viewDidLoad()
        imagePicker.delegate = self


               var logos = [#imageLiteral(resourceName: "MIT Logo"), #imageLiteral(resourceName: "Stanford Logo"), #imageLiteral(resourceName: "Harvard Logo")]

        var pos1 = Int()
        var pos2 = Int()
        var pos3 = Int()

        pos1 = 0
        pos2 = 1
        pos3 = 2

        self.MITImageView.image = logos[pos1]
        self.StanfordImageView.image = logos[pos2]
        self.HarvardImageView.image = logos[pos3]
        // Do any additional setup after loading the view.
    }

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



}



class imagePickerClass : DetailsViewController {

    var pos1 = Int()
    var pos2 = Int()
    var pos3 = Int()
    var MITImage = Int()
    var StanfordImage = Int()
    var HarvardImage = Int()



    init (){
        pos1 = 0
        pos2 = 1
        pos3 = 2
        MITImage = 3
        StanfordImage = 3
        HarvardImage = 3

        let code = NSCoder()
        super.init(coder: code)!
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func imagePickerControllerMIT(picker: UIImagePickerController) {


            self.imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
            weak var weakSelf = self

            weakSelf?.present((weakSelf?.imagePicker)!, animated: true, completion: nil)



                self.imagePicker.dismiss(animated: true, completion: {
                    let imageSelected = [UIImagePickerControllerOriginalImage] as! UIImage
                    var logos = [#imageLiteral(resourceName: "MIT Logo"), #imageLiteral(resourceName: "Stanford Logo"), #imageLiteral(resourceName: "Harvard Logo"), imageSelected]
                    self.MITImageView.image = logos[self.MITImage]


            })


    }

    func imagePickerControllerStanford(picker: UIImagePickerController) {
        imagePicker.dismiss(animated: true, completion: {
            self.imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
            weak var weakSelf = self
            weakSelf?.present((weakSelf?.imagePicker)!, animated: true, completion: {
            let  imageSelected = [UIImagePickerControllerOriginalImage] as! UIImage
            var logos = [#imageLiteral(resourceName: "MIT Logo"), #imageLiteral(resourceName: "Stanford Logo"), #imageLiteral(resourceName: "Harvard Logo"), imageSelected]
            self.MITImageView.image = logos[self.StanfordImage]

            })

        })
    }


    func imagePickerControllerHarvard(picker: UIImagePickerController) {
        imagePicker.dismiss(animated: true, completion: {
            self.imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
            weak var weakSelf = self
            weakSelf?.present((weakSelf?.imagePicker)!, animated: true, completion: {
            let imageSelected = [UIImagePickerControllerOriginalImage] as! UIImage
            var logos = [#imageLiteral(resourceName: "MIT Logo"), #imageLiteral(resourceName: "Stanford Logo"), #imageLiteral(resourceName: "Harvard Logo"), imageSelected]
            self.MITImageView.image = logos[self.HarvardImage]

            })
        })
    }



}

Heres the error

class AppDelegate: UIResponder, UIApplicationDelegate,       UIImagePickerControllerDelegate, UINavigationControllerDelegate {

If you could help me figure this out that would be great.

First want to say that I am using Xcode 7.0 and IOS 9.0 . And I have also got a same problem in objective-c . I found the cause of exception simply debugging my code (Basically which line is responsible for it). And I am going to share with you. Though your question is swift related, I am just trying to help about the signal 1: SIGABRT . It's may help you.

1. First set a debug pointer of your code at any line. click show the break point navigator icon.

2. click create a break point icon.

3. click Add Exception BreakPoint .

4. Right click on the All Exception and click Edit BreakPoint .

5. select objective-c as an option of 'Exception'.

And run your application. It will take you to the corresponding line for which you get SIGABRT .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM