Chris Hannah

Counting Enum Cases in Swift 4.2

Previous to Swift 4.2, the way you (or at least, I) count the number of cases in an Enum, would be to create an extra case called lastValue, or count. This, of course, was only useful if the raw type was an Int.

enum Option: Int {
    case one
    case two
    case count
}

Option.count.rawValue

Well now, if you make it conform to the CaseIterable protocol, you can use the allCases array. Which is generated automatically, and contains all the cases in the order they were defined.

enum Option: CaseIterable {
    case one
    case two
}

Option.allCases.count

This also means you can not only use it to count the amount of cases, but iterate over all of them much easier.

The allCases value is only generated when the Enum doesn’t use associated values, in which case you will have to do this manually.

enum Option: CaseIterable {
    case one
    case two(Bool)
static var allCases: [Option] = [.one, .two(true)]
}

Slate Development Log #7

Just a small update.

After putting a task in Slate off for at least a few months, I’ve got a big chunk of work out of the way, which makes future development so much easier.

Basically, when I first started developing the different sections (Timeline, Mentions, Discover, and Favourites), the code was completely split, and usually badly copied across classes.

I’ve done some work with protocols and inheritance, and now the before mentioned 4 parts of the app are using 99% the same code, except from the slight change in context. For example Mentions is exactly the same, other than a title change, and a few letters in the API endpoint.

As with most other people, WWDC is taking up a lot of time for me. So I think after I do just a tiny bit more work on composing posts, I’ll send another build out. I have composing working in my current build, but my 2 minimum requirements for the next public beta is a minimal version of Markdown formatting, and also replying to posts.

My New Swift Tips Blog

Regarding my ramblings yesterday about starting a new blog for swift development tips, I’ve decided I will host it on my main blog.

However, it is a separate category, that is excluded from the main feeds. There’s still a link in the navigation bar though.

The first post is super simple, and the actual tip is 1 line of code. It’s how to hide extra separators on a UITableView.

I may try and work out a schedule for regular posts, but it may just be slightly sporadic. It’s not going to be full of big tutorials though, I’d rather just share small tips for now.

Automate your financial life with Monzo and IFTTT

We believe that a truly smart bank should empower people to manage their money in a way that suits them. Today, we’re proud to announce that we’re the first bank to partner with the world’s largest automation platform — IFTTT!

In a nutshell, IFTTT lets you personalise how you manage your money. You can create your own rules, called Applets, to connect your Monzo account to the services you regularly use. For example, say you use the iOS Health app to log your calories. With IFTTT, you could enable our pre-made Applet that means every time you buy anything at Starbucks, you’ll automatically log 200 calories on iOS Health.

Yet nother reason why Monzo is the best bank in the world.

Read about Monzo’s IFTTT Integration.

Automatic Workout Detection

If there’s one thing I forget to do, is start a workout when I go out for a walk (I don’t run). But thankfully, watchOS will now detect when you’re starting a workout, and then prompt you to start one.

It appears as a notification on your watch, and from there you can start a workout, without navigating to the app itself. I’ve also seen this appear on my watch (I use the Siri Watch face), but I’m not sure if this is a Siri suggestion based around past behaviour, rather than detecting a workout at that point in time.

You might think that you’d lose some of the data if you waited until the notification appeared, but it also retroactively collects all the workout data, and adds it to the new workout. That’s really an extra step, and makes it such a great addition.

I walk a lot, and I hardly ever start a workout on my watch, either because I’ve forgot, or I just can’t be bothered. I’m hoping this detection is reliable enough to make me never need to start one manually again. But that could just be me being lazy.

It supports 8 types of workouts, and they’re the most common:

  • Outdoor/Indoor Run
  • Outdoor/Indoor Walk
  • Elliptical
  • Rower
  • Pool/Open Water Swim

Oh, and if you think that isn’t good enough, it also has the same detection for when you’ve ended your workout, and it will prompt you to end it on your watch.

Read more of my coverage of WWDC here.

Improvements to Notifications

Very unsurprisingly, iOS 12 brings better notifications support. There’s not too many changes, but they are certainly most welcome.

The big one is grouped notifications. It’s probably the notification feature I’ve been wanting the most, and Android constantly used to make me jealous with it.

I’ve not quite worked out the requirements for them to group together, because I’ve seen iMessage conversations automatically group, but other apps group after 4 or so individual notifications.

There are three options for grouping your notifications, automatic, by app, and of course, none. The interesting one is automatic grouping, because apps can actually help the OS work out what notifications should be grouped together, by providing different identifiers. I’m not going too too much in the technical side, but you’ll notice that Messages.app will group messages from conversations together, but each of these are separate on your lock screen.

There’s going to be more to find out about grouping though, as I’m sure there are different quantifiers which will change the way the system handles them.

In regard to the actions you can take on notifications, you now get to control how any apps notifications are configured, right on the lock screen. All you need to do is swipe right-to-left, and tap Manage. Then you’ll find three different options (depending on the current settings):

  • Deliver Quietly/Prominently (The opposite of what is currently set)
  • Turn Off
  • Settings (This takes you straight to the app’s notification settings, so you can fine tune all of the settings.

These are all welcome options, and I particularly like the deliver quietly, for apps that I want information from, but don’t care that much about it. The options have always been available for these settings, but they’ve always been a hassle to get to. And the Quietly/Prominent options make it simple and clear so everybody can understand.

Do Not Disturb

Something else related to notifications, is the Do Not Disturb, which also received a few improvements.

It’s actually been split into two different levels of not disturbing you, and that’s differentiated by the Bedtime Mode option. So normally Do Not Disturb just means not to notify you, but if you turn on Bedtime Mode, it will keep your screen completely free of distractions until the time period is over, or you turn it off. Something that makes a lot of sense.

It also benefits from “Siri” (the intelligence in your device, rather than the voice), because it’s something else it can suggest for you. It can be triggered by a time, location, or event. I’ve already seen this a few times, once where it suggested I turned it on, but only until an event in my calendar was over. Pretty clever.

These are some fantastic improvements to how notifications work in iOS, but I still would like one more thing from Android. And that is to set specific notification categories. You can do this already as an app, in that it’s the way iOS can group notifications. But Android users can select to mute specific categories from apps, making it an even more personalised system. However, that’s very much want, and not a need.


Read more of my coverage of WWDC here.

Screen Time

If you read my recent piece on refining how I use my devices to maximise their value, you’ll know that the one major thing I wanted to help this was more insight into how I used them. Screen Time is that thing.

In the most Apple way, the data is accompanied with pretty graphs, and there’s quite a bit of information available. You see the apps that have taken up your screen, how many notifications you receive from each app, how often you pick up the phone, and even what your longest session was.

I haven’t received one yet, of course, but Screen Time will also give you a weekly activity summary. Which would be a good time to reflect on how the week went, and then take measures to ensure you use your devices in the ideal way.

If you want to be more strict with yourself, there’s some settings you can play around with, to ensure you know when to stop looking at your phone.

Downtime is a period of time where you will not be able to open any applications that are not in your Allowed list, ideal for setting a strict bedtime. Then you have App Limits, where you set an amount of time that you’re allowed to use on a specific app, or category, and they can even be specific for each day of the week. Finally, there’s a bunch more restrictions you put on yourself, but these apply more to parents who want to stop their children from accessing certain content, or just ensure they don’t just sit on Minecraft all day (what I used to do).

I’m super happy with this feature, and I can’t wait to see my first weekly report. Although I imagine this weeks will be completely skewed, as I’m using my device more than usual to try and find any cool new things in the beta.


Read more of my coverage of WWDC here.

Siri Shortcuts and the Shortcuts App

Kicking off my collection of writing on WWDC 2018, I’m going to talk about Siri Shortcuts, and the Shortcuts app. As soon as I saw it, I knew it would be one of my favourites from the whole event.

The announcement was received by most people as being “now we know what the Workflow team have been up to”, I’m not complaining, I also posted the same thing. It is probably the best way the Workflow acquisition could have gone, because now it’s completely tied into the OS. It may have a different name, but it will always be Workflow.

The features announced was really how the OS interacted with the shortcuts, and how Siri is more intelligent because of it. Not the voice Siri, but the computational Siri that can understand you, and suggest things.

It will, of course, require developers to open up about different user actions in their apps. Which will allow Siri to analyse their usage, suggest them later on, and also maybe for users to build with in the Shortcuts app.

There were some intriguing demos for the suggested actions, which is not something I really say, because usually they are based around unrealistic or ideal situations. But because Siri is in your phone? I’m not sure how to explain that, but it knows about you, what you’re like, and also the environment around you. Which is why it can suggest you turn on Do Not Disturb when you go to the cinema.

They also showed an example of a regularly occurring event, such as buying a coffee in the morning. Maybe not everyone buys a coffee from an app on their phone every day, but I use the Starbucks app every time I go. And that could easily be at least 3 times a week. So if it learned (or just used Maps) the location of Starbucks, recognised it was associated with that action, that would be very helpful! It’s certainly something I feel would be capable, and it’s not a usual Siri feature that’s nice to think about, but never use.

It does get more advance though, and that’s with the Shortcuts (Workflow) app. I conceptualise it by being similar to Scenes in HomeKit, where you could say a phrase such as “Good morning”, and then Siri can perform a bunch of tasks to set you up for the day. Maybe it sort of encompasses the automation of HomeKit?

I’ve already been playing around on the iOS 12 beta, and while I’ve already been suggested some actions, like enabling a alarm, messaging my girlfriend, and even adding a new to-do in Things, we don’t have the Shortcuts app yet. That will come in a later update via the App Store. So I will definitely have to write more about that in the future. But from the keynote, it looks like they’ve added the Apple-style to Workflow, which will definitely make it feel easier to use for general users.

One of my questions though, is how well suited is this to a general user? I will be very keen to see if it’s a widely adopted feature, and even if the Shortcuts app with custom actions might not be, I see the Siri suggestions being a bit hit.


Read more of my coverage of WWDC here.

My Top Picks From WWDC 18

After watching the Keynote, I was thoroughly impressed. While there still isn’t a dark mode for iOS, I can imagine it coming soon. And there are a lot of cool things that were announced.

While watching the event, I took a note of the top 4 for each OS, excluding tvOS, because who cares?

So here they are:

iOS 12

  • Siri Shortcuts
  • Notifications
  • Screen Time
  • Memoji

watchOS 5

  • Competitions
  • Automatic Workout Detection
  • Walkie Talkie
  • Interactive Notifications

macOS Mojave

  • Dark Mode
  • Dynamic Desktop
  • News
  • Mac App Store

I plan on doing some writing about the new features, but in more of an opinionated way, rather than a simple informative guide. You’ll find these with the WWDC 18 tag.