Created
September 11, 2021 23:44
-
-
Save RustyKnight/61e5da25c74b526257d121698d9d058d to your computer and use it in GitHub Desktop.
Testing UserDefaults set(nil, forKey:) and removeObject(forKey:) to see size difference in the plist store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var greeting = "Hello, playground" | |
let key = "Test" | |
let value = "test".data(using: .utf8)! | |
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() | |
// Use this to find the path of the plist | |
//var path: [AnyObject] = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true) as [AnyObject] | |
//let folder: String = path[0] as! String | |
//NSLog("Your NSUserDefaults are stored in this folder: %@/Preferences", folder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment