In my UI test I'm trying to force some user defaults. It seems that one can override them with code such as:
var app = XCUIApplication()
app.launchArguments += ["-myUserDefaultKey", "value"]
app.launch()
But I would like to replace the value of a default where the key contains whitespaces, such as the key created automatically when setting NSSplitView.autosaveName = "someSplitView"
, which is NSSplitView Subview Frames someSplitView
. I tried escaping the whitespaces with NSSplitView\\ Subview\\ Frames\\ someSplitView
and putting the key between single or double quotes, but nothing helped. Is this somehow possible?
Also, what would be the preferred way of temporarily removing a user default instead of overwriting it?
I’ve not played around with the XCTest side of this but it seems to work at the Foundation level. I added code to my app that does this:
print(UserDefaults.standard.string(forKey: "Standard Greeting") ?? "nil")
I then set my Xcode arguments to this:
"-Standard Greeting" "Hello Cruel World!"
At which point my code prints:
Hello Cruel World!
It even works from Terminal:
% ./Test726603.app/Contents/MacOS/Test726603 '-Standard Greeting' 'Hello Cruel World!'
Hello Cruel World!
Note I used single quotes in Terminal because otherwise it tries to interpret the !
.
> what would be the preferred way of temporarily removing a user default > instead of overwriting it?
AFAIK that’s not possible from using command-line arguments.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"