I want to prepare my segue via:
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
if segue?.identifier != "fromOpenChatsToLogIn" {
if let controller: ChatViewController? = segue?.destinationViewController as? ChatViewController {
if let cell: onlineUserCell? = sender as? onlineUserCell {
let user = OneRoster.userFromRosterAtIndexPath(indexPath: tableView.indexPathForCell(cell!)!)
controller!.recipient = user
}
}
}
}
where onlineUserCell
is my custom cell. Also, that's my userFromRosterAtIndexPath:
class func userFromRosterAtIndexPath(indexPath indexPath: NSIndexPath) -> XMPPUserCoreDataStorageObject {
return sharedInstance.fetchedResultsController()!.objectAtIndexPath(indexPath) as! XMPPUserCoreDataStorageObject
}
so, when I select my cell it crashes with:
fatal error: unexpectedly found nil while unwrapping an Optional value
on line:
let user = OneRoster.userFromRosterAtIndexPath(indexPath: tableView.indexPathForCell(cell!)!)
What is wrong? How can I fix it?