I went from not-too-excited about the HomePod a month ago to my third getting delivered tomorrow. It’s great if you use Apple stuff. Quite expensive, but great.

Equatable Swift (NS)Objects

How to implement equality with different kinds of Swift objects was pretty obvious once I read the documentation, but the errors I got at first were not entirely clear. If you want to show equality between two objects in Swift, you have to do something different depending on if they subclass NSObject or not.

In the case of an NSObject subclass, you would override -isEqual::

override func isEqual(to object: Any?) -> Bool {
    guard let myObject = object as? MyClass else {
        return false
    }
    return uniqueID == myObject.uniqueID 
}

If it’s a pure Swift object, however, you would implement the Equatable protocol and override ==:

extension MyClass: Equatable {
    static func ==(lhs: MyClass, rhs: MyClass) -> Bool {
        return lhs.uniqueID == rhs.uniqueID
    }
}

If you try to implement Equatable on an NSObject subclass, you will either get compiler errors about redundant conformance, or your implementation of == will never be called and you will be confused.

Moving to Managed WordPress

Until now I’ve been hosting my blog myself using WebFaction, and it’s worked great. That was until a couple of months ago when I received a notification from my host that they’d detected malware in my WordPress install and my site would remain deactivated until I fixed it. As far as I could tell I was running the latest version of WordPress with a secure password. I have no idea what happened, although I’m reasonably sure it was my fault somehow. I decided to look for another host.

The things that I wanted were to be able to keep using MarsEdit, to have it be secure, not to have to worry if I got a lot of traffic all of a sudden, and for migration (in, and out) to be painless. The obvious choice was to export my blog to WordPress.com and pay for one of their premium plans.

If I decide to move back to self-hosting in the future, it won’t be any harder than it was before, and I shouldn’t have to worry about security or any of that going forward. I will try to post in the future about how it’s working out and what the tradeoffs have been.

Installing Fonts Using Homebrew

I had no idea you could do this, but now that I do, but it turns out you can install fonts from the command line using Homebrew. That means I could write a shell script to install automatically most or all of the fonts I use on new Macs.

I could even have the script in Dropbox and have it run periodically in the background using a launchd service to keep everything in sync. That is useful.

All you need to do is this:

brew tap caskroom/fonts
brew cask install font-<name-of-font>

It looks like it has all of the major free programming fonts and a bunch of others too. Neat.

Opt Out of Junk Mail

For no reason today I thought to Google “opt out of junk mail”, which lead me to an FTC page which describes how you can do just that. It takes about ninety seconds.

  1. Go to www.optoutprescreen.com to opt out of all credit card offers for five years.
  2. Pay $2 at www.DMAchoice.org and you can opt out of seemingly all other junk mail for ten years.

We’ll see how it works, but I assume if it’s linked to from the FTC website it’s pretty legit.