Are the following two lines equivalent?
1.
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@\"example key\"]
2.
[[NSUserDefa
Swift 5.0 + iOS 11 and up
Both methods remove the value. Tried this in a playground:
import Foundation
let key = "Test"
let value = "test"
let defaults = UserDefaults.standard
func printUD() {
print("UserDefaults after modification:\n")
defaults.dictionaryRepresentation().forEach { print("\($0): \($1)\n") }
print("-------------\n\n")
}
defaults.set(value, forKey: key); printUD()
defaults.set(nil, forKey: key); printUD()
defaults.set(value, forKey: key); printUD()
defaults.removeObject(forKey: key); printUD()
Prior to iOS 11 this will result in serializing nil into Data and throw an error.