UIKeyCommand — Part 1: The Basics

This post is the first in a series of three on UIKeyCommands on iOS. In this first post, we’ll go over UIKeyCommand at a high level.

What are UIKeyCommands?

UIKeyCommands represent a key press (or combination of key presses) on a hardware keyboard that will trigger an action. In short, you can think of these as keyboard shortcuts. The system already has a few built-in keyboard shortcuts. Some of these are keyboard shortcuts are Cut (⌘ + x), Copy (⌘ + c), and Paste (⌘ + v).

Beginning in iOS 7, Apple started allowing developers to implement keyboard shortcuts. The system already handles Cut, Copy and Paste and developers won’t need to implement these.

These keyboard shortcuts have been around for a few years. So, it’s easy to see how other developers have implemented these. A great way to discover what keyboard shortcuts apps have is to launch the app, and then hold down the command (⌘) key. Here’s an example from my app Beer Style Guidelines.

iPad Keyboard Shortcut Discovery

How do I implement my own UIKeyCommand?

There are two parts to implement UIKeyCommands in your app. First, is the UIKeyCommand object itself. Then these UIKeyCommands need to be integrated into the app.

The initializer for UIKeyCommand has a lot going on. You don’t need to use every parameter. Here are the minimum parameters to create a UIKeyCommand object. Those parameters are:

  • title: This is the display title of the keyboard shortcut.
  • action: This parameter points to the method that gets called from this shortcut.
  • input: This is the keyboard key (a string) that is part of the keyboard shortcut. For example, the “c” in the Copy shortcut (⌘ + c)
  • modifierFlags: This is the modifying key that is the other part of the keyboard shortcut. For example, the “⌘” in the Copy shortcut (⌘ + c)

Putting all of this together, you can create a keyboard shortcut like this:

    let infoCommand = UIKeyCommand(title: "Show Info",
                                   action: #selector(showInfo),
                                   input: "i",
                                   modifierFlags: .command)
Swift code snippet to create a keyboard shortcut

In this example, the user will trigger a keyboard shortcut to show info when they use ⌘ + i. This will show them an iOS alert with a simple message in it.

I’ve created a sample app that pulls all the various pieces together. The sample app, is simple. It has a single keyboard shortcut. You can discover this just like keyboard shortcuts in other iOS apps.

Download and run the sample app. Once launched, hold down on the Command key (⌘) until you see the prompt showing the single keyboard shortcut within the app.

Testing in the simulator.

If nothing shows up, and you’re testing this in the simulator, you may need to enable “Send Keyboard Input to Device” in the simulator. This can be done through the menu system by selecting I/O → Input → Send Keyboard Input to Device. Or, you can click on this button in the toolbar (below) of the simulator. Without doing this, sometimes the keyboard shortcuts can be lost, and it will seem like the keyboard shortcuts are not working.

Send Keyboard Input to Device

That’s it. Keyboard shortcuts are straightforward to set up and get working in your apps. Next time we’ll get a little more in-depth on UIKeyCommand.

Part 2Part 3

Finally Watching WWDC 2019 Videos

I’ve finally had a minute (or 60) to sit down and start watching videos from WWDC 2019. I know, I’m over a month late to the show.

I watched both the Keynote and Platforms State of the Union on the first day of WWDC. But since then, I’ve been so busy with work and other stuff that I haven’t had much time to catch up.

From the keynote and state of the union videos, I knew SwiftUI looked amazing. But I didn’t get a real sense of it until this week.

I watched Introducing SwiftUI: Building Your First App. That was such a good video/session. I feel like I need to watch it again. I’m also looking forward to watching the other SwiftUI videos and learning much more about SwiftUI.

I think Apple really nailed it with SwiftUI. It looks so simple and intuitive. I should be able to remove a lot of code in my personal apps (and eventually professional apps) because of SwiftUI.

Tonight, I had a chance to sit down and start tinkering with SwiftUI. I currently feel like I’m lost in the woods with some things. It’s a bit overwhelming at first. There’s a lot going on that I don’t know how to do yet (interaction with Timers and Core Data). I need to watch more of Apple’s videos and really dig into the code a bit more.

I’ve got plans to update both MyCntdwn and Beer Style Guidelines to use SwiftUI (among other new features). I’m really hoping that I get good chunks of time this Summer to really dive in and learn the new stuff.

I just hope I have some time to actually make updates to my apps. Like for real this time. Things are so busy with the kids, that I rarely have much time to do this sort of thing anymore.

But this Summer, I’m determined to watch many more videos from WWDC and incorporate new technologies into my apps.

DC Universe

DC Universe is a new product that my company (Warner Bros. Digital Labs) recently shipped.

It’s a project that a lot of us in the company have been working on for almost two years now. We’ve had other projects to work on during that time, but during the last few months, this has taken center stage during our days, nights and weekends.

I’ve spent a lot of time working on the comic book reader for both iOS and tvOS. I’ve worked on other parts of the app(s), but my “baby” was the comic book reader(s). They aren’t perfect and I could probably tell you everything that’s wrong with them. But I’m proud of how they turned out. The iOS/tvOS comic book reader(s) were both written (mostly) by me and from scratch. It was nice to see something like that come to fruition.

We had a very rough Summer getting it ready for consumers and finally released it on September 12th. There was a bit of time where I wasn’t sure if we would ship the app. But we all pulled through and shipped an amazing app.

The DC Universe app was featured on day one. Since then, we’ve had an App Store Story featured about the app. That was a really good feeling. It was also a first for me and any project I’ve worked on before. We’ve had a few apps featured, but never had an app store story about them.

We recently released an update that featured some original content (Titans) that was developed explicitly for the app. It’s something that we’ve been talking about for a long time and it’s finally out for others to enjoy too.

I know the entire team was proud of what we have built. I’m not sure what’s coming next for the app and service, but it will be fun to watch.

My Development Toolbox

As a developer, there are a handful of tools that I use (almost) every day. I thought I would write a blog post about them.

This post is about my the applications that I use every day for development. It doesn’t really get into my office/desk setup or some of my favorite applications. Only what I use on a day to day basis in order to get my job (as an iOS/tvOS developer) done.

Maybe in a future post, I’ll go more into my office/desk setup. I’ll save that for another time.

Xcode

Xcode is my primary development tool. It’s an Integrated Development Environment (IDE). Its got everything I need including a source editor, interface builder, compiler, profiling tools and much more.

I both love and hate Xcode on a daily basis.

Xcode has gotten much better over the years. It still has it’s moments. On most days, I really appreciate it and what it gives me as a developer.

There is at least one alternative to Xcode. AppCode has been around a while. I’ve tried it before and even purchased a license a few years ago. I’ve just never been able to fully commit to AppCode. I don’t know why, but I haven’t. I’ve stuck with Xcode instead.

Xcode is available on the Mac App Store for free.

Charles Proxy

Charles Proxy is an HTTP proxy/monitor application. It allows you to monitor web traffic from a variety of sources, including macOS/iOS/tvOS devices and the iOS/tvOS simulator.

Charles Proxy is a great tool. I don’t use it every day. I do use it 3-4 times a week. I like Charles Proxy so much that I’ve written about it before. Not just once, but twice.

I use Charles Proxy to look at the web data coming into the apps I develop over the network. I’m usually looking for a few things.

Firstly, I need to see what that data looks like coming across the Internet into the apps that I write. I need to know what it looks like so that I can use that data properly within the app.

Secondly, when there are issues with our apps, I like to make sure the data we’re getting from the services we use are what we’re expecting and seeing in the app.

Charles Proxy is available through their site for $50 (USD).

Tower

Tower is a source control client for Git. We use Git (through GitHub) at work and I use GitHub and BitBucket for my personal projects. Tower is a great tool for both of these sources.

I used to use SourceTree, but a change in the app about a year ago lead me to look for another tool. I don’t even remember what the change was, I just knew it was time for a change. I asked on Twitter for suggestions, and Tower was the overwhelming response.

During the writing of this post, I was describing how I wish Tower could squash commits. GitUp was one of the tools I tried while looking for a new Git client and it allows commits to be squashed. Turns out, Tower will allow you to squash commits. The instructions on how to do this is here. It’s not super intuitive, but I’m glad I’ve figured out how to do it.

Tower is available through their site for $69 (USD) a year.

Dash (with Alfred integration)

Dash is the perfect document browser. I use it constantly throughout the day for iOS and tvOS documentation. But it’s not limited to iOS/tvOS documentation. You can download documentation for almost any language or tool that you can think of.

Dash is perfect with Alfred. Alfred is an application launcher, but it’s so much more. If you purchase the Powerpack, you can set up (or install) more complicated workflows. One of these workflows I have is to launch Dash and search for terms I’m looking for. So, I will trigger Alfred (option + space) and then type dash {search term} and Dash will be launched and search for what I’m looking for. This doesn’t seem like a big deal, but it saves me a few steps dozens of times a day.

Dash is available through their site for $29.99 (USD) Alfred is available through their site for free. The Alfred Powerpack is available through the site for £19 (GBP).

Bear

Bear is a note taking app. I’ve got notes for everything in that app. I track my 1:1 meeting notes with managers and other folks. I track general conversations. I’ve got outlines on application and component designs in there. I’ve even got video game notes in there.

I could just use the built in Notes app, but Bear is much nicer. I love the built in Markdown support. I use Markdown for just about everything (documentation-wise). Bear supporting Markdown has made it my go-to note-taking app.

I have just started tinkering with Agenda, which is a different note taking app. I haven’t used it enough to make a decision one way or the other.

Bear is available on the Mac App Store for $14.99 (USD) a year.

Honorable Mentions

Here are some development apps that I love, but don’t use every day, or even on a weekly basis. They are great apps and I thought I would mention them.

BBEdit

BBEdit is a text editor. It’s a super simple, but (almost) perfect text editor. I’ve been using it forever. I think I got my first version of BBEdit in the late 90s. The first version I got came in a box and I’ve been using it ever since.

I learned how to write code in BBEdit. Sure, it was HTML, Javascript and CSS, but it started me down the path to where I am now.

BBEdit is perfect for editing single (or multiple) source files in a large variety of languages. I’ve used it for everything from HTML, to CSS, too Ruby, to Java, to Swift and Objective-C.

I don’t use BBEdit every day, but I do use it a lot. It almost made it onto the non-honorable mention list, but I left it off since I may only use it every other week. It will always have a special place in my heart.

BBEdit is available through their site for $49.99 (USD)

Paw

Paw is an HTTP client app. It can make HTTP requests to APIs and display the results to you in a variety of ways. This is a network tool, like Charles Proxy, but is used differently. This tool is to send requests to an API and inspect the results.

I use Paw a lot when I’m being introduced to a new API. I use it when I need to learn how call an API and what to expect from that API.

I will use Paw heavily when learning a new API, but once I’ve learned how that API works, I won’t use Paw as much.

Paw is available through their site for $49.99 (USD)

Soulver

Soulver is a fancy calculator. That simplifies things a bit. But I use it as a calculator/scratchpad. Instead of writing down numbers and doing calculations on paper, I use Soulver. I have a bunch of “scratchpads” in my iCloud account for a variety of different things.

Soulver is available on the Mac App Store for $11.99 (USD).

Supporting Developers

A lot of the apps I use have free alternatives. But I am a big believer in supporting app developers who do quality work. I use more apps than I have listed here, but these are my daily development apps.

In future blog posts, I may also go into my office/desk setup and other non-work related apps I use day to day.

WWDC 2018

I was lucky enough to be able to attend Apple’s Worldwide Developer Conference this year. This was my fourth time attending the conference, but was my first time attending WWDC in San Jose.

The conference for me had a rough start. It started at home with a four hour delay of my flight. This meant I didn’t get into San Francisco and then to my hotel until after 11pm (2am EDT).

Things got much better after that. The conference was great. I had a great flight home, being moved to an exit row and having an empty seat next to me.

Overall, the conference was great. I did forget much of what I had learned by the end of the week. So many great sessions and things started to blur together.

Favorite “Features” of Upcoming Releases

Apple announced a number of new features and technologies this year.

  • iOS Performance updates
  • Long-form audio on watchOS
  • Dark Mode on macOS
  • Update DND
  • Screen Time
  • Siri Shortcuts
  • CreateML
  • Shared App Platform (early preview)

Favorite Sessions

I watched a lot of sessions while I was at the conference. Here are some of my favorites. I haven’t seen all of the sessions from WWDC, so there may be a number of better sessions out there.

My favorite session was probably What’s New in Swift. I love using Swift. It’s such a great language. I enjoy seeing what’s new in it.

Labs

The labs are probably the largest benefit to coming to WWDC. You can watch the sessions anytime from the comfort of your home. But labs give you an opportunity to talk 1:1 with Apple engineers.

I spent a bit of time in the labs talking and discussing issues I (and my team) have had. We were able to work through most of the issues I brought with me. There was an issue that the engineers weren’t able to solve. I ended up speaking to four different engineers and we decided to create a bug report with as much details as I could give. Hopefully, they’ll come back with an answer at some point (and not just mark it as a dup) and weren’t just trying to get rid of me.

I’m glad that I went prepared with a list of questions and issues to take to the labs.

Most Anticipated Feature

My single most anticipated feature is the ability to have apps play long-form audio on watchOS. I take multiple long walks every day and listen to either books (using Audible) or podcast (using Overcast / Castro). I would love to ditch the phone and walk with my AirPods and Apple Watch.

This feature alone will make daily walks much more enjoyable. I cannot wait for the app developers to implement this new feature.

Overall

It was a great conference. It started out a little shaky, but ended great. I’m looking forward to playing with the new features.

OlderNewer