Josh Betz

Engineer, Automattician, Wisconsin Badger

Wire

Wire is an RSS reader for iOS that displays articles with their native formatting — or an optimized mobile version for sites that support AMP — and doesn’t require yet another account to sign up for.

As mentioned previously, it had been quite some time since I wrote any iOS apps, so I decided to use some of my free time this summer to build an app that I wanted to use.

There are other RSS readers. It’s not exactly new territory. But like most apps, the good ones all seem to require you to sign up for another account. I don’t know about you, but I find the number of accounts I already have to worry about somewhat overwhelming. I don’t need anymore. Relying on an iCloud account won’t solve this problem for everyone, but in this case it solves it for me.

The other main feature I wanted in an RSS reader was the ability to disable the monotonous E-reader-like view that has become so common. So many of the websites I read look great on mobile.

As you can see, it’s a pretty standard design. There’s a simple list of articles that you can group however you want. The article view loads a selected article in a web view. I really prefer this real view of the site to the reader-ized version other apps use.

I have found Wire to be quite good for what I want. It doesn’t do much more than aggregate articles from the websites you want to keep up with, but I think it does that well.

pb – MacOS CLI Trick

You can already interact with the system clipboard in MacOS directly from the command line with two commands: pbcopy and pbpaste. I’ve made it even easier for myself by detecting whether there is data in STDIN — for example if we’re sending data to the command via a pipe. If so, I’ve assumed we actually want to use pbpaste. Otherwise, we want to use pbcopy.

pb () {
	if [ -t 0 ]; then
		pbpaste
	else
		pbcopy
	fi
}

You can use it like pb < /path/to/file or pb > /path/to/other/file, for example.

CSS Dark Mode

MacOS Mojave introduced Dark Mode, which allows MacOS users to enable a darker interface. According to Apple:

In Dark Mode, the system adopts a darker color palette for all windows, views, menus, and controls. The system also uses more vibrancy to make foreground content stand out against the darker backgrounds.

In Safari Technology Preview 68, they’ve also added support for websites to add support for Dark Mode with a new media query:

@media (prefers-color-scheme: dark)

I’ve added support to my theme, which now looks like this in the latest Safari Technology Preview if you’ve got Dark Mode enabled:

Core Data & Concurrency

It’s been a while since I last worked on any mobile apps, so I thought the last couple weeks of sabbatical would be a good time to get caught up on iOS and specifically to learn Swift, which didn’t exist last time 🙃. For the most part, it was pretty easy to pick up and I was able to move fairly quickly on some apps I had been thinking about.

One of the only problems I ran into was related to Core Data concurrency. Specifically, if two different threads are reading and writing data, you get errors like 'NSGenericException', reason: Collection <__NSArrayM: 0x7fabb400> was mutated while being enumerated.

The solution is private queue contexts. I won’t do a full explanation of queue contexts here, but the Apple Developer Documentation has some good information. The idea is to create a private context to operate on while we’re doing background work.

For this to work as expected there are a few things that need to happen:

  1. Set context.parent. In order for the changes to eventually be written to disk, we have to associate the new, private context with the main context by setting newContext.parent = oldContext.
  2. Use context.object(with: objectID) to make core data relationships. We need to get a reference in the current context to any objects that were created outside the context.
  3. After saving, we also need to save the parent context to commit the changes to disk. To make it thread safe, we use oldContext.perform or oldContext.performAndWait depending on whether is should be asynchronous or not.

I put together a gist to demonstrate:

The following articles were especially helpful to understand how to fix this problem in my case:

  1. Apple’s Core Data Programming Guide > Concurrency
  2. Core Data Concurrency & Maintaining a Silky Smooth UI

Eurotrip

This summer I took a sabbatical that included five weeks in Europe. We stayed in 10 cities in 8 countries and took some day trips that pushed the total number of cities to 12 or 13. Needless to say, it was a lot of travel. I don’t know if I would do something quite like it again, but would absolute recommend it if you have the chance.

I didn’t bring a laptop and basically just had my phone, camera, a few books, and my clothes. Here are some of the photos. 

Next Page »