My first post in SE so please go gently on me.... :)
I'm new to swift and iOS dev but have been learning over the last few months.
I have an app that I use to hold dates and values via NSCoder
and encodeObjectForKey
. I pass NSDate
values into this and can decode them with no issues.
However, if I try to pass in nil to overwrite the existing value it appears this is not stored because the old value is returned after the value is decoded and returned.
I searched and found that passing nil to the encodeObjectForKey
method appears to be valid, but I can't find anything that tells me if this will work when overworking an existing value with nil.
Can anyone provide guidance on how to delete the existing value?
My code:
aCoder.encodeObject(dateSold, forKey: PropertyKey.dateSoldKey)
let dateSold = aDecoder.decodeObjectForKey(PropertyKey.dateSoldKey) as? NSDate
Edit: Seems my updated date value of Nil is not making it back across the segue to the class which saves the updates and calls the encodeObject. I shall go and investigate. Apologies for the time wasting....