How do I fix the error of 'Could not cast value of type'?

I am having an issue with this error. If keeps going to my segue. Is there a way to fix this. Any and all help is much appreciated.

Here's my View Controller

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    ***let rvc = segue.destinationViewController as! WebViewController***
    rvc.currentCollege = currentCollege
}

And heres my class:

import Foundation

class College {
    var webView = String()
    var name = String()
    var description = String()
    var location = String()
    var numberOfStudents = String()
    var image = String()


    init(Name n: String,Description d: String,Location l: String,NumberOfStudents s: String,Image i:String, WebView w: String) {
        name = n
        description = d
        location = l
        numberOfStudents = s
        image = i
        webView = w
    }
    init(){
        name = ""
        description = ""
        image = ""
        webView = ""
    }
}

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
        let currentCell = tableView.dequeueReusableCellWithIdentifier("myCell")!
        let currentCollege = collegeArray[indexPath.row]
        currentCell.textLabel!.text = currentCollege.name
        currentCell.detailTextLabel?.text = currentCollege.location
        return currentCell
    }

Answers


I'm guessing that destinationViewController is not a WebViewController. Perhaps WebViewController is embedded in a navigation controller You could do something like:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if let rvc = segue.destinationViewController as? WebViewController {
        rvc.currentCollege = currentCollege
    }
}

To avoid force down casting in prepareForSegue.


Need Your Help