I have a fairly large and complex NSManagedObject
that I'm manipulating within my application and sending back to a server as JSON. My plan was to do what I need to do in my application, convert the object to a Dictionary, and then send it along after calling NSJSONSerialization.dataWithJSONObject
(I've also tried using SwiftyJSON
, which I think is doing more or less the same thing). This was all working fine until I needed to include some dates.
Basically all of the documentation I've seen says that serialization works just fine with a certain list of object types, which does not include NSDate
. Sadly, I need some dates. I should note that I am working with a dictionary of dictionaries that may have dates scattered all up and down the tree, so if I recursively run through to convert them all to strings I'm going to have to do a whole lot of copying to NSMutable
dictionaries. Surely there's an easier way? I'm a bit new to Swift and iOS development and I can't help feeling like I'm either doing something wrong or that there is a built-in solution to this problem that I'm just missing. I can't be the first person who wants to send back a date as JSON. Any help would be much appreciated.
Thanks, Alex