Save and retrieve the CGPath in CoreData iOS swift
Problem:
I want to save the CGpath to the Coredata and retrieve the path and redraw it.
Solution:
Save to coredata:
From coredata and redraw:
I want to save the CGpath to the Coredata and retrieve the path and redraw it.
Solution:
Save to coredata:
let objDict = NSMutableDictionary()
objDict.setValue(NSKeyedArchiver.archivedData(withRootObject: Color), forKey: "color")
let bezierPath = UIBezierPath(cgPath: tool.penPath)
objDict.setValue(bezierPath, forKey: "Path")
objDict.setValue(NSNumber(value: Double(tool.lineWidth)), forKey: "width")
From coredata and redraw:
let path = k.value(forKey: "Path")
let shapeView: CAShapeLayer = CAShapeLayer.init()
shapeView.path = (path as! UIBezierPath).cgPath
shapeView.strokeColor = UIColor.white.cgColor
shapeView.lineWidth = CGFloat(k.value(forKey: "width") as! Double) self.ciew.layer.addSublayer(shapeView)
Comments
Post a Comment