AnsweredAssumed Answered

How do I serialize & de-serialize a AGSPolyline object?

Question asked by UncleRic on Mar 10, 2017
Latest reply on Mar 10, 2017 by UncleRic

Environment: iOS/Swift 3

Goal: to save a AGSPolyline object within a dictionary for UserDefaults; and retrieve the object back as a AGSPolyline


Modus Operandi: storing the AGSPolyline within a dictionary for persistent UserDefault.

The following code is my first attempt; it crashes due to the AGSPolyline object not being serialized.

I thought I cut use the NSKeyedArchiver, being that AGSPolyline is an NSObject.   But it fails with a run-time crash:


func storeSketch(doodle:AGSPolyline) {

        var myDict = [String:AnyObject]()

        var key = SketchItem.Polyline.desc()


        let json = doodle.encodeToJSON()

        let myData =  NSKeyedArchiver.archivedData(withRootObject: doodle)

        myDict[key] = myData as AnyObject?

        key = SketchItem.Doodle.desc()

        UserDefaults.standard.set(myDict, forKey: key)




I believe I need to JSON-SERIALIZE (and JSON-DE-SERIALIZE) my AGSPolyline object (a Geometry object) so I can insert it into my dictionary for UserDefaults storage.


How do I do that?

What's the syntax?

... or can I transform a AGSPolyline object to a common NSObject (NSData??)... and go from there?