Ugly Swift Syntax for Checking Errors

A common code pattern I see a lot in iOS code is:

service.execute(request) { (response, error) in
    if let error = error {
        handleError(error)
        return
    }

    // work with response...
}

I don’t like that if statement. I’d much rather use a guard statement.

For those who don’t know guard, the docs explain:

A guard statement, like an if statement, executes statements depending on the Boolean value of an expression. You use a guard statement to require that a condition must be true in order for the code after the guard statement to be executed.

I like guard over if cause it’s more expressive about my intentions that the code after it should only run if there was no error found. Unfortunately, because of the boolean nature of the guard clause, to do this requires using Implicitly Unwrapped Optionals.

service.execute(request) { (response, error) in
    guard error == nil else {
        handleError(error!)
        return
    }

    // work with response...
}

I really try to avoid Implicitly Unwrapped Optionals, so much so I use SwiftLint to throw warnings for their use. Adding lint exceptions for this regular occurrence, for me, is not an option.

If you have more control over the service implementation you might choose to use a Result type.

enum Result<T> {
    case success(T)
    case failure(Error)
}

service.execute(request) { (result) in
    switch result {
    case .failure(let error):
        handleError(error)
    case .success(let response):
        handleResponse(response)
    }
}

I generally like this but it doesn’t work if you need to support a mixed Swift/Objective-C environment. It also doesn’t account UIKit itself does not use a Result type.

Code should be beautiful and so I think it’s important to document these things. I’d love to find a better solution and welcome feedback.

Hello Firefox, Goodbye Chrome

A few weeks ago I said to myself, enough was enough and dropped the Chrome web browser.

If you aren’t actively following the web development world it’s easy to miss, but Google and Chrome have really been hostile toward the open web over the last few years. A few examples:

In 2016 Google introduced Accelerated Mobile Pages. From its wikipedia page:

AMP has been widely criticized by many in the tech industry for being an attempt by Google to exert its dominance on the Web by dictating how websites are built and monetized, and that “AMP is Google’s attempt to lock publishers into its ecosystem”. AMP has also been linked to Google’s attempt to deprecate URLs so that users will not be able to immediately see whether they are viewing a webpage on the open Web or an AMP page that is hosted on Google’s servers. AMP has been described as being “poisonous to the underlying concept of an open internet.”

In Chrome 68 they began to deprecate HTTP and now list HTTP sites as insecure.

In Chrome 69 they added a behavior that strips the www subdomain from the URL bar. (Try visiting www.mikezornek.com and it becomes mikezornek.com. This may feel like a small thing for users but as a developer its a firm violation for how the web URL works.

Just this weekend I read a story of some more shenanigans:

Matthew Green:

A few weeks ago Google shipped an update to Chrome that fundamentally changes the sign-in experience. From now on, every time you log into a Google property (for example, Gmail), Chrome will automatically sign the browser into your Google account for you. It’ll do this without asking, or even explicitly notifying you.

Paul Frazee:

There’s a reason people are reacting to Chrome like this. This isn’t an overreaction over one single event. It’s a delayed reaction to a pattern of bad behavior.

It’s contextualized by the very messed-up power dynamic between Google and the open Web.

Google’s influence over the web through its search was already over the line in many ways but to see its once celebrated browser go down this road is depressing.

Actions speak and Firefox is treating me well. I now use it across my computers and devices, from MacOS to iOS and even my Windows gaming tower. DuckDuckGo is my default search engine (and has been for like a year now) and works well too. It feels good to be using products from people who share my interests to heart.

WWDC 2018 Social Recap

I just got back from my WWDC 2018 Social trip and it was a lot of fun. I figured I’d do a quick recap of the social side and leave room to talk about the tech stuff as I get deeper into the session videos in the weeks to come.

Costs

With a nod to Manton’s lead I thought I too would share my costs in order to help others understand what is possible despite WWDC generally being a large cost these days.

  • Plane fare (Southwest, Philadelphia to San Jose Roundtrip taking the early and late times to save a little bit extra): $564.00
  • Hotel: ($125/night, 4 nights + taxes & early checkin fee). Booked early on event date assumptions, was cancelable.: $642.00
  • Airport cab fair: $25 each way.
  • WWDC conference ticket: $0 (Big savings here obviously. If you can get value from the labs, the $1700 ticket cost can pay for itself but if you just want to watch the sessions, enjoy the free video streams on delay).
  • AltConf conference ticket: $0 (I’ve bought the $300 Hero ticket in the past but held back this year since I’m on my own again and trying to keep costs down. Kind of feel bad considering how well I enjoyed the talks there this year.)
  • Food and drinks: ~$300 Made a point to get some supplies at a grocery store early in the week so I could supplement eating out with some in-room breakfast mornings and snacks.
  • Podcast and other event tickets: ~$50

Total: ~$1600

TL;DR: Make your decision about WWDC early and keep an eye on the rumored dates. Book early with hotels that are cancelable. If you need some more help, find a roommate to split hotel/cab costs with.

Events

On Sunday night I attended the sjMacIndie party and saw a lot of conference friends. Venue was a little on the warm side but plenty of space so it didn’t get too stuffy. I did not recognize much of San Jose from my earlier WWDC trips (2002-2004) but I did recognize this venue as the previous pool hall where the student scholarship winners once had a party. In fact it was at said party where I won an iPod which I later sold to help cover my plane fare back in the day.

You can check out some of the old WWDC 2002 Student coverage we did via Wayback Machine and this video, with footage from the pool hall, I was able to find and re-upload.

On Monday I watched the Keynote and State of the Union with friends at the hotel. We had to jump wifi networks a few times but overall was very successful. Afterwords I headed to the live recording of ATP podcast which was a lot of fun.

On Tuesday I took in a few AltConf talks and also attended the Micro.Blog meetup. Really enjoyed the Setapp talk about their growth/recommendations and the detailed talk on improving app startup times. I also took some time on Tuesday to work on my own project, finally breaking down a long list of tasks into a new Pivotal Tracker project so I can start to track things better.

On Wednesday did more AltConf stuff. Really enjoyed Paul Hudson’s review of new iOS 12 additions. Also had a good time in the Finding Product Fit lab. At night I attended the Relay FM podcast recording which went great. Afterwords I went to the Breakpoint / AppCampForGirls event. I didn’t stay too long though, place was really dark and loud. Also kind of irked me that there was a separate VIP section. I really dislike the social cliques that pop up at industry conferences and seeing the VIP thing put a bad taste in my mouth.

Aside: I’d love to see some options for non-bar night events at conferences. A 24 hour hacking lab with whiteboard grouping around ideas; maybe with room corners for Mario Karting or boardgames/poker. I like hanging out but I don’t like drinking too much and I can’t hear people over the crowds. I miss MacHack in many ways. Maybe I’ll lead by example some day should I ever dawn my event organizer hat again.

On Thursday I got to attend a few morning talks at AltConf before heading home. Of them I really enjoyed the review of what Firebase is offering these days. I’ve been watching them since before they were bought by Google. Like any third-party component you have to accept some risk but I welcome the opportunity to use them to bootstrap a new idea some time in the future.

The journey home took a long while. I didn’t sleep much but did enjoy a bunch of podcasts.

Overall WWDC 2018 Social was a great success. It was awesome to say hi to some internet/conference friends and hear how everyone is doing. Now that I’m home it’s time to jump into the technical content and see what the WWDC sessions have to share. I’ll post more on that as I experiment.

Right to Repair

Via phoneArena:

It has been reported that iOS 11.3 has disabled some iPhone 8 touch displays. The devices affected are those who have had third party displays installed. These displays are typically installed by local repair shops and are not affiliated with Apple.

I’ve been a supporter of the Right to Repair movement and Apple once again disappoints. Perhaps the issue is a anomaly but if the past is pattern and without providing comment, then it feels like spite.

Louis Rossman has a good breakdown video you can watch for more info.

UPDATE: Another relivent story today: FTC: Warranty-voiding language like Nintendo’s and Sony’s is illegal

Rethinking My Music Storage

I’m not a huge music collector, at least not compared to some other people I know. I do have about 150 GBs of music in my iTunes collection — lots of it being video game soundtracks I enjoy listening to while I program.

A few things I have not liked about my historic setup:

  • Because the collection was 150 GB I could not store it on my main computer’s SSD (which was 256 GB in size).
  • iTunes sucks. I don’t want to get into details here but as a music player and organization tool it’s awful.

Some goals for my new setup:

  • I want to get rid of iTunes.
  • I’d like to store my music on Dropbox, preferably in a way where I can control which Music (if any) gets synced to my other Dropbox setups.
  • I have recently become a Spotify member. It’s got a nice collection I feel I can lean on AND it has some tools the player UI to support local files as well as streaming songs which I think will be key.

With all that said, what I’m up to:

First thing, I made a new iTunes library on my desktop and have started re-downloading my old iTunes music purchases. I have lots of music that is still DRM wrapped and these new downloads do not have such DRM.

Next, I’m going to slowly start to put the music into Dropbox. I’ll have a root level Music folder but inside I’m going to split the collection into Rare and Common. Common being for songs that are streamable from Spotify and thus being a folder I can selectively NOT sync on my other computers. The Rare folder will have all of my video game soundtracks and other albums I find to be incomplete or missing on Spotify. As I said, I like how Spotify can bring in local music into playlists and even lets you control the source folders and I’m hopeful this will work nicely.

We’ll see how it goes over the next few weeks. I’d love to hear if anyone else has an exotic setup like this.

Also, next up for a rethink is photos. Again, I’m really not happy with the current Apple solution and am thinking of alternatives. Feedback welcome.

You Don’t End Schindler’s List with a Pepsi Ad.

It’s Friday. I’m actually a little low energy and so I decide to go out and pick up a late lunch. I’ll eat it in my car listening to a podcast and get some outside / sun time. The podcast of choice is Startup, a podcast about starting a business to make podcasts. It’s a good show, with interesting stories and high production values. It’s in season 4 so we are well past the pitch stuff and into the real forced growth issues that all VCs seem to face.

Today was a particularly powerful episode of Startup with lots of emotion. It even had me a little teary eyed. Then the end came, but it was not the true end. We still had an upbeat MailChimp ad, read by the same podcaster who just seconds ago had us all in tears.

It was one of the most drastic shifts of emotional voice I can remember and it had me rolling my eyes with bewilderment.

You don’t do this. You don’t play the heart strings of your audience and then shove an ad down their throat while they are in the moment. You don’t end Schindler’s List with a Pepsi ad.

The producers of this show are professionals. They are listening to these audio cuts many, many times over, but I suspect they aren’t doing it with the Mailchimp ads weaved in. Maybe they should.

The lesson here, once again is empathy. We need to constantly work to put ourselves in the shoes of our audience. If you have something important or emotional to share with your audience, you don’t weave it into your revenue system. I totally accept the need to use ads for some systems but if you must show ads, maybe for a show with an arc like this you show an extra one in the beginning so you can end clean? Doing it like this just seems emotionally tone deaf for me.

The World Needs a Better Core Data

Lots of WWDC predictions out there this week. Here’s a dream of mine. Sadly one that I’ve given up on, at least from Apple.

A Better Core Data.

  • Tracking state is 1970s thinking. We should be tracking changes over time and rendering the current state of the object graph.
  • Migrations, the number one feature. As you add new entities to a store, you do so through a migration. Change a column name, you do it through a migration. The current Core Data migration story is embarrassingly complex and very fragile. We need to have trust in our migrations.
  • A single, focused, persistent store format. Allowing people to choose between XML, Binary, SQLite, InMemory and Custom adds more pain than it solves. Keep things simple. One on-disk format.

A Walled Garden of Shit

From the App Store Review Guidelines:

We have over a million Apps in the App Store. If your App doesn’t do something useful, unique or provide some form of lasting entertainment, it may not be accepted.

I sure wish they would take that guideline to heart and start rejecting some of this shit.

So PBG got an iPad and found some shitty iPad games and I’d like to say these are the exception — but they’re not. There are tons of these crappy apps on the store and while it helps inflate that “total app” number for Apple it really hurts people browsing around trying to discover new apps.

WEIRD IPAD GAMES!

iOS Development: Things to Like; Things to Hate

Things I like about iOS Development

  • I like writing code in the Objective-C language.
  • I like Apple’s provided frameworks and tools. They are, on the whole, very good.
  • I like the iOS community’s enthusiasm for great products. It is very inspiring.
  • I like that people will pay you good money to build apps for them in iOS. Though this is has good and bad implications.
  • I love attending, and over the last few years running, CocoaHeads in Philadelphia.
  • I like that the community on a whole is not very secretive. There is a sense we are in this together and people constantly help each other out sharing tips, code and war stories.

Things I hate about iOS Development

  • I hate the exclusivity of the AppStore distribution.
  • I hate that I can’t side load apps that people build that Apple doesn’t approve of.
  • I hate that I have to sign my apps.
  • I hate the learning curve and the bugs of the signing process for all but especially for people new to iOS.
  • I hate that Apple has a shitty code validator during app signing that will complain when I have methods on my objects that look like private methods on their objects.
  • I hate how shitty AppStore search and discovery is.
  • I hate the corporate politics that let apps get featured in the store because of “connections”.
  • I hate how people continue to manipulate the AppStore ranking system and I hate how little Apple seems improve the situation when many small developers livelihoods are at stake.
  • I hate how the Radar bug system doesn’t have tools in place to involve and update the original bug reporter on progress being made. From a third-party perspective most bug reports might as well go into a black hole.
  • I hate how in the pit of my stomach I believe that, on the whole, the iPhone and its brethren have not improved society. I think the majority of mobile software has only helped to empower “generation ‘me'”, a generation that is “friends” with everyone, but no one. This deserves a post on to itself someday.
  • I hate the iOS / Mobile bubble. The fact that people are spending way too much building apps and are not getting a proper return of value on the investment.
  • I hate that building products is way riskier than consulting (bubble related).
  • I hate that Apple hasn’t shown more interest in providing a library management system. Thankfully we have CocoaPods but since it’s on the outside there is a fear it might not be able to keep up as the tool chain evolves.
  • I hate that back when Apple first started to integrate OCUnit into Xcode it enviably killed like 3 or 4 other very promising testing systems because the thought at the time was “well Apple made their choice and will build on it” when in fact Apple never did. Only recently did we see XCTest and it is, right now from a functional perspective, a method renamed version of OCUnit with no new features.
  • I hate how Xcode Bots doesn’t have pre and post scripts.
  • I hate (hate is a strong word — let’s say disappointed by) the growing community of “Apple Celebrity”. The once full time developers who can build great things but now choose to spend the majority of their time blogging, podcasting and tweeting all day. They partake in a low impact ping pong match of opinions on weekly events and news that frankly doesn’t mean all that much in the grand scheme of things.