store cgpoint in userdefaults iOS swift
Problem:
I want to store CGPoint in userdefaults.How can i achieve that?
Solution:
You have to convert the cgpoint to string then save it in userdefaults.
// MARK: - set and get the Add button frame
func getBtnBounds()->CGPoint? {
if let obj = self.userDefaults.object(forKe
let point = NSCoder.cgPoint(for:obj)
return point
} else {
return nil
}
}
func setBtnBounds(value: CGPoint) {
let pointValue = NSCoder.string(for: value)
self.userDefaults.set(
self.saveValue()
}
Comments
Post a Comment