reojased reojased - 1 year ago 84
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")

Answer Source

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()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download