I cannot seem to find the answer to this problem. Hopefully someone here will be able to help.
I'm trying to Encode/Decode an object in order to store it in UserDefaults. My object contains a Dictionary object contining a key, with an array of user-defined objects. No matter what I do or try i cannot get the encoder to encode the Dictionary object. All other properties encode/decode without issue.
All members of the MyUserDefinedClass are basic types and have encode/decode methods that work without issue.
I've tried everything I can think of trying to get this to work ... breaking it down by parts; Keys and Values ... nothing works.
Any help would be "Greatly" appreicated
Swift Code example:
@objc func encodeWithCoder(aCoder: NSCoder)
{
// Other objects encoded here
if let myDictionary = self.myDictionaryObject
{
// gives me an error that cannot encodeObject with myDictionaryObject type
aCoder.encodeObject(myDictionary, forKey: "myDictionaryObject")
}
}
@objc required init(coder aDecoder: NSCoder)
{
// other objects decoded here
// This compiles with no error or warning
self.myDictionaryObject = aDecoder.decodeObjectForKey("myDictionaryObject") as? Dictionary
}
// myDictionaryObject
var myDictionaryObject = Dictionary<Int, [MyUserDefinedClass]>!
Thanks, Gary