Daniel Tull: Notes

Sunday, 12 April 2020

Week four of social distancing due to COVID-19 and I’m starting something new. Welcome to my notes! These aren’t linked by subject, but simply things I found this week that may be of interest. There’s no structure here, so I imagine it will evolve and sections will come and go. I suspect it’s mostly for future me, either desparately trying to find a link among these pages or for the nostalgia of the past. 😅

Articles

Videos

Code

I accidentally clicked don’t allow on an OBS permission and I didn’t see which one it was. Turns out you can reset an app’s permissions on macOS (Stack Exchange).

tccutil reset All
tccutil reset AppleEvents
tccutil reset All com.apple.Terminal

Needing to resize Xcode to be the right size for streaming, I found this link with some AppleScript to do that. Thanks Amit!

(*
This Apple script will resize any program window to an exact size and the window is then moved to the center of your screen. Specify the program name, height and width below and run the script.

Written by Amit Agarwal on December 10, 2013
*)

set theApp to "Xcode"
set appHeight to 1080
set appWidth to 1920

tell application "Finder"
	set screenResolution to bounds of window of desktop
end tell

set screenWidth to item 3 of screenResolution
set screenHeight to item 4 of screenResolution

tell application theApp
	activate
	reopen
	set yAxis to (screenHeight - appHeight) / 2 as integer
	set xAxis to (screenWidth - appWidth) / 2 as integer
	set the bounds of the first window to { xAxis, yAxis, appWidth + xAxis, appHeight + yAxis }
end tell

More use of the obtuse for case let syntax (thanks Tim Vermeulen).

for case let viewController as MyProtocol in viewControllers { ... }

Checking a Result<Void, Error> in a test in Swift.

The following will crash out if the test fails which is not good as the crash will halt all other tests and give little output as to what the failure was.

XCTAssertTrue((try? result.get())! == ())

It’s better to replace it checking the result is not nil.

XCTAssertNotNil(try? result.get())

When switching on a result, you can check for a specific error in the failure case to handle it differently from all other errors.

switch result {

case .success:
    authDelegate.signInSuccess()

case .failure(AuthError.actionCancelled):
    authDelegate.signInCancelled()

case .failure(let error):
    authDelegate.signInFailed(with: error)
}