Swift: Launch at Login

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.


  • What is the license of this code? Is it okay to use in App for the Appstore? Maybe you could clarify the license.

    • BSD. Not suitable for App Store — google around, that generally needs a separate helper app

      • Hi erica, could you show the other way on Swift? with separate helper app?

  • Oh, yes, btw this method is doesn’t work anymore… on 10.11+ 🙁