Created
January 12, 2018 07:39
-
-
Save immortalsantee/2ff57b0d05e94c65b766c7d3f9f8e0ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rect = CGRect(x: 0, y: 0, width: 100, height: 100) | |
let circleBezierPath = UIBezierPath(roundedRect: rect, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: rect.width/2, height: rect.height/2)) | |
// 1. Get Data from BezierPath | |
let bezierData = circleBezierPath.smGetData() | |
// 2. Store bezierData in user defaults | |
UserDefaults.standard.set(bezierData, forKey: "com.santosh.bezierPath") | |
// 3. Get BezierData from userdefaults | |
let myBezierData = UserDefaults.standard.data(forKey: "com.santosh.bezierPath") | |
// 4. Get back bezier path from data | |
let myBezierPath: UIBezierPath? = myBezierData?.smGetBezierPath() | |
extension UIBezierPath { | |
func smGetData() -> Data { | |
let bezierData = NSKeyedArchiver.archivedData(withRootObject: self) | |
return bezierData | |
} | |
} | |
extension Data { | |
func smGetBezierPath() -> UIBezierPath? { | |
if let bezierPath = NSKeyedUnarchiver.unarchiveObject(with: self) as? UIBezierPath { | |
return bezierPath | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment