Hi
I have my tableView Controller where I have my CoreData objects. In my case I’ve managed to save my team using CoreData (Thanks @hollance).
The next part for me is being able to add players to this team, So I followed the same appraoch as done in earlier chapters but with arrays. So I have this in my TeamViewController
else if segue.identifier == "ViewPlayers" {
if let navigationController = segue.destinationViewController as? UINavigationController {
if let controller = navigationController.topViewController as? PlayerViewController {
// add players from this team to table
if let indexPath = tableView.indexPathForCell(sender as! UITableViewCell){
let currentTeam = teams[indexPath.row]
controller.team = currentTeam
}
}
}
}
In My PlayerViewController I have:
class PlayerViewController: UITableViewController, PlayerDetailViewControllerDelegate {
var team = Team!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.rowHeight = 66.0
// set navigation bar title
if let currentTeam = team {
title = currentTeam.name
}
}
...
This is giving me errors that I don’t understand how to fix in this CoreData context though
In TableViewController the error is: Cannot assign value of type 'Team' to type 'Team!.Type' (aka 'ImplicitlyUnwrappedOptional<Team>.Type')
In the PlayerViewController it’s: Expected member name or constructor call after type name
that’s for the line var team = Team!
and Initializer for conditional binding must have Optional type, not 'Team!.Type' (aka 'ImplicitlyUnwrappedOptional<Team>.Type')
that’s for if let currentTeam = team {...
I’m confused as to the problem here when using CoreData and not an array and how to fix it? Especially the first error
What did I do wrong?