Renaming a widget extension
I’m working on an update for my formulary app. Among other improvements, this update will add widgets.
Minimize the number of test assertions
Recently I wrote a tweet about demo code shown by an Apple engineer in a WWDC session.
Xcode - Move Focus
Use the shortcut
⌘ Jto move focus between editors.
The View Debugger in Xcode
When ever I have a problem in the user inteface of and app or when I just need to confirm that my assumptions about the user interface are correct, I start the View Debugger in Xcode. When the app is running in the Simulator, Xcode shows the debug bar. The icon with the three squares viewed from the side, halts the execution of the app (like a breakpoint does) and opens the View Debugger with the current view.
The environment our apps are running in is complex. There is dark and light mode, the font size can change because of Dynamic Type, the user can ask to deactivate animations or to increase contrast. A good app manage to look and work good in all these circumstances. We as developers are responsible to respect all these environment variables.
The Contextual Action Menu
Use the shortcut ⇧⌘A or select the menu item ‘Editor / Show Code Actions’ to open a contextual action menu. The menu items depend on the position of the cursor.
Find A Problematic View In The View Debugger
I’m quite confident that you have seen a message like this in the debug output (assuming you’ve already used Auto Layout in one of your apps):
The Accessibility Inspector
iOS itself is quite accessible for people with different kind of disabilities. The most prominent accessibility features in iOS are:
The Snippet Library In Xcode
The Snippet library is part of the library in Xcode. You open the library from the menu item ‘View / Show Library’ or with the shortcut ⇧⌘L.
Selector And The Responder Chain
I don’t know about you, but I tend to forget that there is a responder chain in iOS. This post is to remind myself (and you) that the responder chain exists and that we can use it to react to button events.
Record A Video Of Your App In The Simulator
A video of your app running on a device or in the simulator shows the potential users not only the user interface but also how the apps feels like. It shows if the animations are to long and how the parts of the app are connected to each other. You can use such a video to show off your app on social media. Or you can add the video to your app page in the App Store.
The Jump Bar In Xcode
You are using the jump bar all the time when working with Xcode. In case you wonder what I mean with jump bar, it’s this:
Test The Publisher Of A @Published Property
John Sundell wrote a blog post about how to test Combine-based code. In the article he shows how to write unit tests for a publisher that tokenises a string. Great article as always and you should read it.
Automatically Switch to Build Log
One often overlooked feature of Xcode are Behaviors. I will go into more detail about Behaviors and how I used them in a future post.
Make Debugger Console Output Stand Out
Breakpoints are very powerful. One feature of breakpoints I use the most is to print the value of a variable. This can be done by adding the Debugger Command
po myVariableto a breakpoint like this:
Testing the "Untestable"
I often complain on Twitter that SwiftUI code is not testable with unit tests. Every time I get asked what the value of such tests would be.
Xcode - Move Focus to Editor
Xcode comes with many keyboard shortcuts that help to navigate within a project or between the different parts of Xcode itself. To become an efficient Xcode user, you should learn how to use Xcode without reaching to the mouse or the track pad. After adding a new file to the project (⌘N) Xcode sets the focus onto the file in the file navigator. To switch the focus to the editor you can use the shortcut ⌘J.
Xcode Shortcuts I Use The Most
If you want to become an Xcode pro user, you need to look into its shortcuts!
Using Xcode Behaviors
During development, we developers have to wear different hats. Sometimes we are programmers, sometimes we are testers, sometimes we are bug hunters, and sometimes we are archaeologist searching for ancient bugs. Xcode has features for all these roles and Xcode Behaviors can help to automatically switch between these features.
Colors In Xcode
Xcode provides several ways to deal with colors for our projects. Let’s see what options we have as developers.
Scrolling A Collection View With Custom Duration Using CADisplayLink
Last week I needed to scroll a collection view animated to its end with a define duration. Should be easy, right? Just set the content offset of the collection view in an animation block like this:
Don't Put View Code Into Your View Controller
Sometimes I see code that sets up subviews in
viewDidLoad()of a view controller. Be a good citizen and don’t do that. If you have to add something to a view, do it in a
Building An Expanding Circle Transition Between View Controllers
I love custom transitions between view controllers. One of the easiest of these transitions is taking an element from the previous view and animating it to its new place in the next view. For example like shown in this gif:
Adding A Development Menu To Your App
Often during development of an iOS app, I need to navigate to the same part of the app over and over again. Or I need to simulate events like discovery of iBeacons without having the iBeacons around. Or I need to test the look of the view with different data.
Testing a Custom UICollectionViewCompositionalLayout.list
In iOS 14 Apple added a collection view compositional layout that lets us create collection views that look and behave like
UITableViews. It is based on UICollectionViewCompositionalLayout and as a result allows to create very complex collection view layouts with only little code.
Using Tabs in Xcode
Tabs in Xcode can be quite useful. I use them a lot.
Quick Tip: Accessibility Zoom to Debug Layout
Sometimes during the development of an iOS app, you need to figure out, how many pixels are between two views.
CGAffineTransform and Auto Layout
This week at work I had a strange bug in an iOS app. It looked like something was wrong with the Auto Layout constraints. The following screenshot shows a simplified version of the user interface.
Simulating GPS Location Updates in the iOS Simulator
Sometimes when building an iOS app you need to simulate moving around. Let’s say, for example, you create an app that allows the users to draw their movement onto a map. It would be difficult to move around with your iOS device connected to Xcode to debug your code.
Grand Central Dispatch Timer
Last week I needed to fire a timer on a background thread. You can do this with a
Timerthat is added to a run loop on a background thread.
Using breakpoints to populate with demo data
Often during development, you need to populate the view controller with demo data. One solution is to change the code to use dummy data. But this means you have to change the code and remember to change it back when done.
A breakpoint I cannot live without
I’m often working on projects from other devs. Some of the projects are quite complicated and I have difficulties to remember all the view controllers. Here is a breakpoint that helps me a lot when figuring out what’s going on and where I need to fix a bug.
Search and Replace in Xcode
Recently I took the regex course at executeprogram.com. Awesome stuff.
Dynamic Type in UIButtos
Recently I updated my formulary app after three years of absence from the App Store. Now I try to make it the best formulary app in the App Store again. The best formulary app in 2019 needs to support dynamic type.
tl;dr: I put an update of my first app to the App Store. 10 years after it first got approved.
Testing The Presentation Of A View Controller
I’m writing a book about Test-Driven iOS Development with Swift. It’s not a traditional book, it’s mainly only the code. If you are like me and seldom read blog posts but rather skim for the code, this book is for you.
Easy Unit Tests In iOS Development
Testing is hard. That’s why it’s not done enough in iOS development. When I ask other developers, many don’t write unit tests at all. That’s no good. Unit tests are an essential tool to build high quality iOS apps and allow disruptive refactoring without breaking functionalities.
UIStackView was introduces with iOS 9. And from the beginning I loved it. UIStackViews allow to use Auto Layout without adding Auto Layout Constraints. And most of the times you get away with changing a few properties to achieve what you want. You need some time to get used to it though. So back when a beta of iOS 9 was available I created an Xcode Playground to experiment with the new and shiny UIStackViews.
SwiftConf 2018 - Sketch Notes
This year I was able to attend only one conference. And this conference was SwiftConf. I do sketch notes to keep concentrated while listening. I’m not good at this but nevertheless it helps me a lot to recall the talk later.
Debugging View Layouts with Breakpoints
I don’t like the Interface Builder. When doing the interface in code (and even sometimes when using the Interface Builder) I’d like to see at runtime where exactly the views are positioned. Depending on the contents and the background color of the views this is not always easy.
Snapshot tests with iOSSnapshotTestCase
Sometimes you need to add automatic tests for the UI of your app. There are several different approaches to achieve this.
Sketch Notes At UIKonf 2017
I attended UIKonf (iOS developer conference in Berlin) this week. Great conference. I have been at UIKonf in 2014 but this time it was so much better for me because I talked to so many people. It’s not that the people have been more open this time.
Why I Still Don't Like The Interface Builder
Even with the improvements of the Interface Builder in the last years I still prefer doing iOS interfaces in code. Here is why:
subscribe via RSS