UserDefaultsConstant.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // UserDefaultsConstant.swift
  3. // Learn Genie
  4. //
  5. // Created by Suraj Kumar Mandal on 31/08/21.
  6. //
  7. import Foundation
  8. class UserDefaultsConstant {
  9. class func getIntValueFromUserDefults(for key:String) -> Any?{
  10. let userDefault = UserDefaults.standard
  11. return userDefault.value(forKey: key)
  12. }
  13. class func setIntValueInUserDefaults(objValue:Int,for key:String){
  14. let userDefault = UserDefaults.standard
  15. userDefault.set(objValue, forKey: key)
  16. userDefault.synchronize()
  17. }
  18. class func getValueFromUserDefults(for key:String) -> Any?{
  19. let userDefault = UserDefaults.standard
  20. return userDefault.value(forKey: key)
  21. }
  22. class func setValueInUserDefaults(objValue:String,for key:String){
  23. let userDefault = UserDefaults.standard
  24. userDefault.set(objValue, forKey: key)
  25. userDefault.synchronize()
  26. }
  27. class func getBoolValueFromUserDefults(for key:String) -> Any?{
  28. let userDefault = UserDefaults.standard
  29. return userDefault.value(forKey: key)
  30. }
  31. class func setBoolValueInUserDefaults(objValue:Bool,for key:String){
  32. let userDefault = UserDefaults.standard
  33. userDefault.set(objValue, forKey: key)
  34. userDefault.synchronize()
  35. }
  36. class func setObjValueInUserDefaults(objValue:Data,for key:String){
  37. let userDefault = UserDefaults.standard
  38. userDefault.set(objValue, forKey: key)
  39. userDefault.synchronize()
  40. }
  41. class func getObjValueFromUserDefults(for key:String) -> Any?{
  42. let userDefault = UserDefaults.standard
  43. return userDefault.value(forKey: key)
  44. }
  45. class func removeValueFromUserDefults(for key:String){
  46. let userDefault = UserDefaults.standard
  47. return userDefault.removeObject(forKey:key)
  48. }
  49. class func deleteAllValuesFromUserDefaulst() {
  50. let domain = Bundle.main.bundleIdentifier!
  51. UserDefaults.standard.removePersistentDomain(forName: domain)
  52. UserDefaults.standard.synchronize()
  53. print("Deleted")
  54. }
  55. }