reojased reojased - 4 months ago 12
Swift Question

This class is not key value coding-compliant while setting a value in NSDictionary

This is the complete ERROR that appears in my console, I've already looked in some other answered questions but in my case the problem changes, all of the cases I've found on stack overflow or any other web forum has to do with the storyboard or .xib file and a bad reference but in my case it has to do with setting a value in a dictionary, and my class is correctly linked to the storyboard file, the console error is the following and it gets called in this line of code:

"This class is not key value coding-compliant for the key NivelRelevancia."

//diccionario global is my dictionary
var diccionarioGlobal : NSDictionary = [String: AnyObject]()

diccionarioGlobal.setValue(nivelRelevancia, forKey: "NivelRelevancia")


If you want to mutate your dictionary, you should use the dictionary type from the Swift standard library:

var diccionarioGlobal:[String: AnyObject] = [String: AnyObject]()

Or use an NSMutableDictionary, as NSDictionary is immutable:

var diccionarioGlobal = NSMutableDictionary()