WWDC 2016 Labs Highlights

Yogev Sitton
5 min readJun 18, 2016

--

Most of my time in WWDC was spent in the labs — since sessions can be downloaded and watched later. I’ve learned A LOT and I would love to share of this knowledge with you.

Notice — this post will not cover any of the new iOS 10 features or anything from the sessions I did go to. Watch them for yourself!
This post will cover only what I have learned in the labs.

Xcode Open Hours

SourceKit crashes

We have a lot of SourceKit crashes. This causes us to lose autocompletion, colors, cmd+click etc… We don’t know why and it’s annoying as hell.

I tried to understand if there’s a way we can see the crash logs.

Fortunately for us — there is.
Unfortunately for us — it sucks.
But - we’ll take what we can get…

We can’t see logs for crashes that already happened — but we can initiate a debugging session and hope that SourceKit will crash during that session. And let’s face it… It probably will…

Open Terminal and enter the following:

SOURCEKIT_LOGGING=#/Applications/Xcode.app/Contents/MacOS/Xcode

Replace # with the following values:
1 — For requests only
2 — For requests + responses
3 — For requests + responses + notifications

This will allow you to see all of the messages between Xcode and SourceKit. Once SourceKit will crash you should be able to see the line that caused the actual crash and hopefully will provide enough clues to how to deal with it.

External Frameworks

I initially wanted to ask about how to turn some code I’m working on into a framework we import to various apps we build. The requirements were to be able to use it on the same project as a different app (for the ease of changes) but still treat it as a separate framework. I was having some issues doing that myself.

Good thing I did that because turns out we were “doing it wrong” with another framework we were using. Our project was using a Workspace in order to include another framework’s project and add it as dependancy.
Turns out this is a workaround and not how it should be done

Leaving it this way could cause a few problems in the future (the Apple engineer claimed he could think of at least 15 potential issues) plus the chance of being rejected from the app store in some cases (yes — I found it hard to believe as well…).

Here’s the correct way to do it:

  1. Open your app’s project
  2. Drag the framework project into the app’s project
  3. Add the framework as Target Dependency — in the Build Phases tab
  4. Add the framework as Embedded Binary — in the General tab (choose from the product folder)
  5. Add the framework folder to the Frameworks Search Paths — in the Build Settings tab

At this point my project wouldn’t compile anymore.

I added a couple more steps which fixed everything and allowed me to use the framework in the same project without using a Workspace — the way “it should” be done:

6. Tap on the app’s in the project hierarchy and then File->Project Settings

7. Tap on Advanced and change it from Legacy to Xcode Default

You can now remove the existing build folders from the project and Xcode should continue as usual.

Swift Open Hours

Optional Booleans

I was having some issues with reading optional Bool values from Swift to Objective-C. Turns out there is no representation of a Swift optional Bool variable in Objective-C. Unlike optional NSString and NSNumber — which can be nil in Objective-C — Boolean values cannot be nil in Objective-C.
Changing to Bool to a non-optional variable solved the problem.

On Demand Resources Lab

Third party libraries

I already knew the answer — but I felt like I had to ask.
Can we use the On Demand Resources capability in order to lazy load third party libraries like Card.IO?

The answer was, obviously, “NO” — but they were interested in this use case.
They suggested we submit a feature request and it might get things moving. The more duplications in requests the better by the way..

UI Testing And Continuous Integration

Correct workflow when using the record feature

Unfortunately, the record feature is far from perfect. It gives you a nice place to start but there’s a few hours of refactoring after you complete recording a test.

I wanted to make sure I’m not doing anything wrong — and turns out I wasn’t — this is how it works.

A good practice will be to start creating known working test “actions” like “login”, “go to specific screen”, “enter text into search bar”, etc…
Then — we will only need to record very small parts of the test instead of entire flows.

Accessibility labels

We kind of suck with accessibility labels.

A lot of actions I recorded were searching for static text in order to find the UI controls instead of the preferable way — which is accessibility labels.
Adding more accessibility labels through the app will allow for easier and quicker tests creation + the added value of actually having accessibility labels for the hearing impaired.

Reseting the app states after (before) tests

When running a UI tests suit you would probably want to run a few tests that doesn’t rely on each other. Each test should start with a clean app.

That’s why I used to add “delete accounts and logout” actions to the end of tests. The problem is when one test fails in the middle — it also fails to remove the accounts and logout. So following tests will start with the changes that were made by the failing test.

I asked if there’s a way to reset the app state each time a new test starts. There’s no way to do that — but Apple engineer suggested to add a testing flag in the project settings that will be detected by the app (when loading) and will cause it remove all user data when that flag is active (via code).

Timestamped Event Matching Error: Failed to find matching element

When recording a test, selecting an already selected UITableViewCell will cause the test recording to crash with the message “Timestamped Event Matching Error: Failed to find matching element”.

Turns out Apple has an open bug with this exact issue but didn’t know the reproducing steps. So we were both very excited I know exactly how to crash the recording every time.

I still need to create a new project and see if it happens there as well - or is it specifically on my app. I really hope I would be able to help them fix the problem soon.

--

--