UIBezierPath to NSData to Server to Android

1.5k Views Asked by At

currently I have a class that conforms to NSCoding containing a UIBezierPath and a UIColor.

    required init(coder aDecoder: NSCoder) {
        super.init()
        self.lineColor = aDecoder.decodeObjectForKey("color") as! UIColor
        self.bezierPath = aDecoder.decodeObjectForKey("bezier") as! UIBezierPath
    }

    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(lineColor, forKey: "color")
        aCoder.encodeObject(bezierPath, forKey: "bezier")
    }

I achieve this with NSKeyedArchiver

NSKeyedArchiver.archivedDataWithRootObject(path)

and save it on a server (parse.com) I can unarchive it with no problem with iOS. But how to be compatible with Android?

2

There are 2 best solutions below

0
On BEST ANSWER

You'd need to convert the paths and colours into some common format and export it in a common format. Something like SVG including the RGBA values. UIBezierPath and keyed archiving are iOS specific items with private binary implementations - trying to work with them on Android will take you a long time and not be future proof.

0
On

I'd agree with Wain. You can call self.bezierPath.CGPath to retrieve a CGPath, and then you can use the following answer to get it into SVG.

How to convert CGPath to SVG

Then you can send it along in a neutral format.