Software Dev

Singletons – When There Can Be Only One

Like so many smart and courageous people, the Singleton design pattern is often misunderstood.

Whether it is attacked as an anti-pattern, maligned as untestable, or misused as a global convenience, singletons take a lot of ๐Ÿ’ฉ for just being what they are: a way to enforce that there is only ever one of something. I think they should call this pattern “The One”.

A real life example of a singleton is The President of the United States. We only ever have one president at a time. That’s a key part of the concept. It’s not just a convenience.

In software terms, singletons make sense in many cases such as the one and only instance of the current app running on the current iPhone.

With all this in mind, this quick post provides some nice context about singletons (aka the President) versus just a shared instance (hey, let’s all share this one bike) in Swift.

๐Ÿ‘‰ Whatโ€™s the difference between a singleton and a shared instance in Swift?

Thanks to iOS Dev Weekly for calling out the ongoing confusion on this topic. ๐Ÿ™

Software Dev

Getting Started with Instruments

Has there ever been a more powerful, but under-utilised tool than Instruments?

Instruments is a tool included with Xcode that helps you analyze, profile, and debug your live iOS app. Solve memory leaks. Visualize memory. Monitor disk, network, memory, and battery usage. You can even find zombies. ๐ŸงŸโ€โ™‚๏ธ

It lets you do incredible things but is also overwhelming to new developers, in which case this Ray Wenderlich tutorial can come in pretty handy.

๐Ÿ‘‰ Getting Started with Instruments

There’s also an Apple WWDC presentation with this same name. ๐Ÿ˜†

Visual Memory Debugger

Via iOS Dev Weekly.

Software Dev

Motion ๐Ÿ’“

This ๏ฃฟ-centric open-source animation library looks promising.

๐Ÿ‘‰ Motion on GitHub

Motion

Motion is an animation engine for gesturally-driven user interfaces, animations, and interactions on iOS, macOS, and tvOS.

I’ve been a little skeptical of open-source animation platforms since I had to toss out one app and then another as cocos2d morphed into cocosd2x and broke everything. Damn that x! But still, this looks cool. ๐Ÿ‘†

Via iOS Dev Weekly.

Software Dev

The Mac Developer’s Swiss Army Knife

I get so annoyed when I find myself using random websites ๐Ÿคฎ or all different apps ๐Ÿคท๐Ÿปโ€โ™‚๏ธ to do things like format JSON, test regex’s, encode/decode Base64, encode/decode URLs, or convert Unix time strings.

This nifty little Mac app does all the basic things any developer regularly needs natively, locally, and offline. And it’s free if you build it yourself. Or pay for the official build. Up to you.

๐Ÿ‘‰ DevUtils.app – Developer Utilities for macOS

DevUtils.app screenshot

Via iOS Dev Weekly. See also: Mac-assed Mac Appsย ๐Ÿ˜†

Software Dev

It’s Time for Snapshot Testing

I love the idea of snapshot testing. It’s a simple way to automatically test an app’s UI.

It works like this:

  1. Set the app up in a certain state and take a screenshot. Save the screenshot. ๐Ÿ“ธ
  2. Next time when you run the same test, you compare screenshots. ๐Ÿ“ท ๐Ÿ“ธ
  3. If something changed unexpectedly, then you know there’s trouble. ๐Ÿ’ฅ

Here’s a nice series about how to do it for iOS/ Xcode.

๐Ÿ‘‰ Snapshot Testing. Testing the UI and Beyond (Part 1)

And GitHub: swift-snapshot-testing

The coolest thing is that you actually upload your screenshots in any new pull requests, so you can literally see what the change is all about (“The perfect pull request”). ๐Ÿคฏ

Image for post

Via iOS Dev Weekly.

Software Dev

New Wisdom On Configuring Xcode Projects for Different Environments

It seems like it would be simple and/or obvious how to configure your app to point to different environments (dev, QA, prod, etc.). But alas, it is neither simple nor obvious.

Here is some easy, practical wisdom that breaks down five different ways to configure different environments in an Xcode project. Spoiler: it finally lands on Script Phases. ๐Ÿคท๐Ÿปโ€โ™‚๏ธ

๐Ÿ‘‰ How to configure Xcode projects for different environments

First of all, โ—๏ธย do not use targets for environmental configuration purposes

Via iOS Dev Weekly.

Software Dev

The Elm Architecture

I’ve been trying to understand the Elm Architecture for a new iOS project. I kept reading over this article and thinking, “Wait a minute…. What’s the catch here? This seems too simple.” ๐Ÿง

๐Ÿ‘‰ The Elm Architecture: Simple, yet powerful โ€“ An overview by example

I like that this architecture can be explained in a very short post with examples.

The beauty of The Elm Architecture lies in its simplicity.

That article is simple but assumes a web UI and explicit mentions HTML ๐Ÿ™„. Here is a funnier and more useful article about Elm for iOS. ๐Ÿ˜‚

๐Ÿ‘‰ Elm architecture in iOS: Why you donโ€™t need shit like RxSwift or MVVM

Elm architecture can be described as follows

msg -> Model -> View -> msg

I even made my own diagram just to make sure I “got” it. The devil is in the details, but I think this is right. ๐Ÿคท๐Ÿปโ€โ™‚๏ธ It definitely seems simpler than VIPER.