Skip to content

Instantly share code, notes, and snippets.

@keehun
Created October 24, 2019 20:58
Show Gist options
  • Save keehun/7fe492d9f6f69908d562e657e7bb6746 to your computer and use it in GitHub Desktop.
Save keehun/7fe492d9f6f69908d562e657e7bb6746 to your computer and use it in GitHub Desktop.
NSMutableDictionary(contentsOf:error:) Bug (Fixed on Catalina)
import Foundation
let url = FileManager.default.temporaryDirectory.appendingPathComponent("test.plist")
func crashes() throws {
try NSDictionary().write(to: url)
let returned = try NSMutableDictionary(contentsOf: url, error: ())
/// This will crash
returned.setValue("Hello", forKey: "World")
}
func works() throws {
try NSDictionary(dictionary: ["Key" : "InitialValue"]).write(to: url)
let returned = try NSMutableDictionary(contentsOf: url, error: ())
/// This will NOT crash
returned.setValue("Hello", forKey: "World")
}
try? works()
print("works() succeeded")
try? crashes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment