Was helping someone this morning on IRC while waiting for dr’s apt. He was pretty desperate for a launch-at-login check, so I pulled up my old ObjC version and started poking away at a Swift version, which follows. (Note: this is 10.10 and later as I didn’t really feel like including pre-10.10 support for a proof of concept.) I had a few interesting revelations along the way, mostly dealing with the fact that you can’t use a lot of CF items directly as they’re unmanaged.
I doubt I’ve applied the unmanaged-to-value transformations well here as this is the first time I’ve used them. The docs say:
“ The Unmanaged<T> structure provides two methods to convert an unmanaged object to a memory managed object—takeUnretainedValue() and takeRetainedValue(). Both of these methods return the original, unwrapped type of the object. You choose which method to use based on whether the API you are invoking returns an unretained or retained object.”
I suspect I need retained for copy/create and unretained for get but I wish I could apply Project > Analyze and have it tell me whether I’m messing up the memory management here.