Sitemap

Version Two

6 min readJun 14, 2019

--

You don’t have to rewrite your whole app when you want to release version two, in fact, many people would say it’s inadvisable, or worse, to rewrite your whole app! Maybe they are right, this guy sometimes is :) But I think we got away with it.

This week we released v2 of Bullclip for iOS — our wonderful app that allows easier design communication for everyone on architecture and engineering teams. Here is what the project involved, some of the challenges we faced, and some of the lessons we learned.

Press enter or click to view image in full size
Let’s draw!

A Modern App

The app is now written 100% in Swift 5, and fully supports iOS 11 and 12. This has allowed us to move fast, using modern APIs. The app is responsive, useful for split screen on iPad, accessible, fast, stable, and nice too look at — theming was considered from day one.

[Aside: Sticking to modern frameworks and design patterns has proven useful already — a few days after WWDC 19 there was a branch that contained dark mode and multiple windows. Both of those things together took under 8 hours to implement and will be released when iOS 13 is public.]

Get Baz Scott’s stories in your inbox

Join Medium for free to get updates from this writer.

The first lesson is — stick close to Apple design patterns, and keep code up to date, it makes life so much easier.

Press enter or click to view image in full size
Getting to the right PDF

What Does the App Do?

The app can be broken down in to five parts:

  1. Navigating to a PDF — In order for our users to get to the PDF they want to work on a lot of data needs to be fetched and some navigation needs to happen. Things like logging in; auth tokens; listing the users team and projects; fetching lists of drawings; caching of all of these things, etc. This is all in the realms of standard URL and JSON-wrangling.
  2. Rendering a PDF — A lot of research and experimentation went in to this part of the build. Version 1 used Core Graphics to render PDFs but it was not performing optimally and was hard to work with. So we investigated the new (to iOS) PDFKit from Apple. This crashed on about 1/4 of our test PDFs. Our customers in the architecture and engineering space generate very complex and large PDFs so we need to be able to render them reliably. We then tried PDFTron (which we already use to good effect on other platforms) and it performed very well with our test data. So we tweaked the settings on that to provide the best experience in caching without using too much RAM and used that as the baseline for our PDF rendering.
  3. Inking & displaying annotations — We have a variety of inking requirements, from custom freehand drawing to specific shapes and stamps. We also had to build a tool picker, saving of favourite tools, editing of annotations, different interactions if pencil is present vs not, and so much more. This is really the soul of the app, the good stuff. It took many iterations to get our freehand inking algorithm working in a way that feels amazing with pencil or finger, and looks great at 30% zoom or 4,000% zoom without generating way too much data. High fidelity inking while live syncing is very much a game of trade offs. There’s a reason why Apple Notes and OneNote don’t allow you to zoom the documents much, if at all, because allowing for clarity at high zoom levels is directly in conflict with keeping data packets small. We think we have found a really nice balance here.
  4. Syncing engine — Related to the inking/annotations point above is our ability to sync annotations in near real-time. The big complication here is that users must be able to work offline and then sync all of their work when they come back online. So not only do we have to deal with large blocks of data constantly being sent when online (websockets help here), but we have to deal with a queue of these blocks building up too. So far, this article is around 800 words, if I was handwriting this in our app that would be around 2,000 to 3,000 individual annotations, or marks, on the paper, and each of those marks is a decent sized SVG. It’s easy to see how we can quickly generate a lot of data when handwriting offline. Writing this syncing engine was a huge challenge as it has to both send and receive data, work offline, work with or without websockets (some VPNs block them) and it must never ever lose any data :)
  5. Additional features — The app also allows for other features that users need: Comments on drawing, Issues, comments on Issues! And internal features like diagnostics, error reporting, etc.
Press enter or click to view image in full size
Pick a project

What Did We learn?

With an app as complex as this we had to stick to some solid basic principles to get the app written in a good time. Here are some of the things we learned that worked well for us:

  • Use modern Swift, and make heavy use of functional programming concepts and things like Codable. It just makes life easier.
  • Use a layered architecture of small components — We use a sort of MVVM architecture. MVVM with a few other bits bolted on.
  • We make heavy use of protocols to pass actions around and ensure objects are abstracted to useful layers.
  • Dependency injection for everything. Small components are seperate and are given what they need from callers.
  • View controller containment. We make heavy use of this to render all screens as a tree of dependent views.
  • Share common views — e.g. standard loading/error/content containers. (I think this will set us up well for SwiftUI adoption next year)
  • Pretty much all of our data is immutable, until performance dictates otherwise.
  • As we needed offline use, we designed that in from the start using caching and queues. This slowed down initial development but was ultimately faster than retrofitting offline capability later on.
  • Tests, and only merging PRs if they are green.
  • One “AppStyle” file centralises all styles. (And this meant iOS 13 dark mode took about an hour to implement)
  • Stay close to UIKit norms. The app looks great, but it sticks very close to base. There is hardly any UIKit funny business going on. The only place that is not completely stock iOS is the canvas with its toolbars down each side.
  • Not too many dependencies. We have a few, the main one being GRDB as a SQLite wrapper.
  • Singletons are ok, used sparingly. The main singleton we have is the queue that handles syncing of annotations as this has to keep a tight grip on its own internal state while being bombarded with state changes from all sides :)

Stats

As you can see, this was a big undertaking for a small team. It took about 150 elapsed working days. For most of that time we had two people working on the project, sometimes only one, so it wasn’t a huge development team, which I think was an advantage. Of course we had UX, UI, Product, QA, and Sales people to help out too.

We added 419,402 lines of code. But deleted 1,635,757 line of code! (The bulk of that came from removing React Native and other dependencies). Obviously most of the code added is from dependencies — really our code base is ~40,000 LoC, with a few thousand more in tests.

Just one of the contributors

We merged just over 300 Pull Requests to get this done, and completed ~200 story cards in Clubhouse.

Press enter or click to view image in full size
Cumulative Flow Diagram for the project

More Info?

I wanted to write this post to see what people were interested in hearing more about. I intend to write more posts in the future covering some of the topics above in more detail so feel free to reach out and let me know if that would be useful. Thanks for reading!

--

--

Baz Scott
Baz Scott

Written by Baz Scott

Chief Engineer @drawboard. iOS guy in a Microsoft world. Startups & product delivery. Made a Transformers game you probably played. Disabled Scottish chap.