Search code examples
iosswiftseguefilenames

this class is not key value coding-compliant for the key (I changed a file name in Storyboard)


EDIT - This is not a duplicate. Even after all connection were made correctly I still got this error. The actions to correct this issue apparently needed to be completed in a specific order as well. See response marked as answer.

I changed a file name in Storyboard and everything broke. Im getting the error "this class is not key value coding-compliant for the key" but i don't think thats actually the problem. I have a viewcontroller named Draft and another viewcontroller named Draft2. On my storyboard i changed the file name from Draft to Draft3, and then my Draft2 to Draft. I changed the names of the classes respectively and then i deleted the segues and recreated them. I've also changed the view controller Title and Storyboard Id's respectively. I dont really care about Draft3 because it will be deleted eventually but i NEED Draft (the new version) to work.

I've reconnected all of the outlets for the new Viewcontroller named Draft. I've also tried cleaning the program (cmd + shift + k). I have tried saving and closing.

What is going on here?

This is part of my Draft viewController

class Draft: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UISearchBarDelegate {


@IBOutlet weak var battlegroundName: UILabel!
@IBOutlet weak var draftStatus: UILabel!
@IBOutlet weak var draftNotes: UILabel!

@IBOutlet weak var collectionHeroPool: UICollectionView!
@IBOutlet weak var collectionTeam1Bans: UICollectionView!
@IBOutlet weak var collectionTeam2Bans: UICollectionView!
@IBOutlet weak var collectionTeam1Picks: UICollectionView!
@IBOutlet weak var collectionTeam2Picks: UICollectionView!

@IBAction func undoButton(sender: AnyObject) {
    self.navigationController?.popViewControllerAnimated(true)
    self.navigationController?.navigationBarHidden = false
    //dismissViewControllerAnimated(false, completion: nil)
}

var team1First = true
var battleground: Battleground!
var team1 = [Hero]()
var team2 = [Hero]()
var turn = 1
var team1Active = true
var activeTeam = [Hero]()

var team1Bans = [Int: Hero]()
var team2Bans = [Int: Hero]()
var team1Picks = [Int: Hero]()
var team2Picks = [Int: Hero]()
var bans1 = [1,9]
var bans2 = [2,8]
var picks1 = [3, 6, 7, 12, 13]
var picks2 = [4, 5, 10, 11, 14]
var pickedHeroes = [Hero]()




override func viewDidLoad() {
    super.viewDidLoad()


    let value = UIInterfaceOrientation.LandscapeLeft.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")
    self.navigationController?.navigationBarHidden = true

    battlegroundName.text = battleground.name

This code is in my predraft that segues to Draft

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "preDraftToDraft3" {// if this is the segue being loaded with this identifier
        if let detailsVC = segue.destinationViewController as? Draft3 { // grab the view control we will go to and cast it as the hero detail class
                detailsVC.team1First = team1First!
                //print(selectedMap!.name)
                detailsVC.battleground = selectedMap
                //print(detailsVC.battleground.name)
        }
    }
    if segue.identifier == "preDraftToDraft" {// if this is the segue being loaded with this identifier
        if let detailsVC = segue.destinationViewController as? Draft { // grab the view control we will go to and cast it as the hero detail class
            detailsVC.team1First = team1First!
            //print(selectedMap!.name)
            detailsVC.battleground = selectedMap
            //print(detailsVC.battleground.name)
        }
    }
}
@IBAction func startDraft(sender: AnyObject) {
    if team1First != nil && selectedMap != nil {
        performSegueWithIdentifier("preDraftToDraft", sender: nil)
    }
}

Solution

  • Actually you have performed all the right actions but in the wrong order. You need to follow below steps:-

    1. First remove all IBOutlets, IBActions and Segues.
    2. Then change the classnames in ViewControllers source files.
    3. Then change the classname in Storyboard for ViewController scenes.
    4. Now connect Segues, IBOutlets and IBActions.
    5. Clean, build and run. That should work.

    Cheers!