Created
October 24, 2019 20:58
-
-
Save keehun/7fe492d9f6f69908d562e657e7bb6746 to your computer and use it in GitHub Desktop.
NSMutableDictionary(contentsOf:error:) Bug (Fixed on Catalina)
This file contains 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 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