signal SIGABRT error in viewController

时间:2016-04-04 17:28:44

标签: ios xcode swift uiviewcontroller segue

Hi I am not good at Swift and am getting a signal error. I couldn't find anything that can cause it. I really want to finish this app, can someone help me please.

error-video https://www.dropbox.com/s/xlvo22fvurivize/error.mov?dl=0

Since I just use option-drag for the segue I am not sure it is related with the code. Should I add something in that class, maybe there is something that I missed ?

Could not cast value of type 'recipeApplication.ViewController' (0x1041ff030) to 'recipeApplication.matchesPageViewController' (0x1041ff0d0).

This is the error.

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let matchesPage: matchesPageViewController = segue.destinationViewController as! matchesPageViewController

    for var i = 0, a = 0 ; i < data(0).2 ; i++ {

        if data(i).0.isSubsetOf(choosenSet) == true {
            self.myMatchedArray.insert(self.data(i).1, atIndex: a)
            a++
        }
    }

    for var i = 0 ; i < myMatchedArray.count ; i++ {
        //print(myMatchedArray[i])
        matchesPage.dataArray.append(myMatchedArray[i])
    }
}

This is the code in my prepareforsegue but like in the video, I have used this one for going another viewController so I did not use it for going back. Like I said I just declared it with a segue ...

Any idea is appreciated. Thanks

1 个答案:

答案 0 :(得分:0)

正如评论中所述,在打印segue.destination时,您收到了<recipeApplication.ViewController: 0x7f9f1a42b670>。这意味着你的segue的目的地是ViewController。但是,您尝试将ViewController转换为matchesPageViewController。这就是你收到错误的原因。你应该检查一下。

if let matchesPage = segue.destinationViewController as? matchesPageViewController {
    //Do code
}

希望这有帮助。