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(forKey"BtnBounds"asString {

            let point = NSCoder.cgPoint(for:obj)

            return point

        } else {

            return nil

        }

    }

    

    func setBtnBounds(valueCGPoint) {

        let pointValue = NSCoder.string(for: value)

      self.userDefaults.set(pointValue, forKey"BtnBounds")

      self.saveValue()

    }


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store