I have M1 chip MacBook Air laptop. I set, remove and get value from UserDefaults.
Below code I set the value
UserDefaults.standard.setValue("my string", forKey: "UserEmail")
Get the value using valueforkey
UserDefaults.standard.value(forKey: "UserEmail")
Remove key from userdefaults using removeObject
UserDefaults.standard.removeObject(forKey: "UserEmail")
Even if I set the value through "UserEmail", I am not able to get the value. Strange thing happened if I run four to five times then sometime I got the value and sometime not in the simulator! I have searched on google, stack overflow and already spent so many hours on this issue but not find any solution.
It only worked if I run this on Actual Device and other laptop that doesn't have M1 chip.
Can anyone help me out What should I do so it will work fine in simulator and on my M1 chip laptop.