Aleksandar • Vacić

iOS bits and pieces

How to invalidate flow collection view layout on rotation

Say you want to have grid layout with cells always half the size of the screen’s width. You want to maintain that layout in both portrait and landscape. Since iOS 8 that can’t be easier, with the right incantations.

First, subclass UICollectionViewFlowLayout.

Then add the following method into it:

- (UICollectionViewLayoutInvalidationContext *)invalidationContextForBoundsChange:(CGRect)newBounds {

  UICollectionViewFlowLayoutInvalidationContext *context = (UICollectionViewFlowLayoutInvalidationContext *)[super invalidationContextForBoundsChange:newBounds];
  context.invalidateFlowLayoutDelegateMetrics = (
                                                 CGRectGetWidth(newBounds) != CGRectGetWidth(self.collectionView.bounds) ||
                                                 CGRectGetHeight(newBounds) != CGRectGetHeight(self.collectionView.bounds)
  return context;

The key here is casting returned context from super as UICollectionViewFlowLayoutInvalidationContext which allows you to toggle the invalidateFlowLayoutDelegateMetrics property. That will tell UIKit that it should re-query FlowLayout’s delegate for the sizes.

In the collection view controller, make sure it’s set to adopt UICollectionViewDelegateFlowLayout protocol and then add this delegate call:

- (CGSize)collectionView:(UICollectionView *)collectionView
                layout:(UICollectionViewFlowLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

  return CGSizeMake(floor(self.view.bounds.size.width/2.0), 88);


How to symbolicate watchOS 2 extension crash logs from device

I’m working on the next version of Run 5k app, which includes standalone watchOS 2 app. In current Xcode 7 beta 4, it takes 30-40mins for the watch .app bundle to get copied from iPhone to the watch device. No idea why it takes so long; it’s even called out as issue in Xcode 7 beta 4 release notes (they promise it will be resolved in future seeds).

The main problem with this is that debugging is next to impossible. Due to this you can’t realistically debug with the devices attached to Xcode so the only way is to install the iOS app, let it copy the watch bundle over and then use the app once it’s done.

My last-night test ended in a very repeatable crash. Great. Crashes from the Apple Watch are always copied to its paired iPhone and you can get them by connecting the iPhone, then opening Windows / Devices in Xcode, then tap “Show device logs” button.

Xcode then goes and symbolicate each .crash log file for you. However, in my case it symbolicated everything except my own code.

I am speaking at VoxxedDays Belgrade 2015

A lively local bunch have taken on themselves to organize a tech conference in Belgrade, at start of October.

Why you should care?

If you are interested in one (or more) of the myriad of topics announced so far, you should get yourself a ticket, which are still in the early bird phase.

Second – have you seen the awesome illustration used as background for the web site? It perfectly illustrates the vibe this conference aims for. :)

Third – October is one of the nicest months to visit this city. Plus the venue is amazing, right in the heart of the downtown Belgrade. If you are unfimilar with Serbia, checkout #MySerbia hashtag on Twitter.

Fourth – I’m speaking on it. ☺️
My talk will be on WatchOS 2 apps with emphasis on what you should do to have a good chance of being featured by App Store editors.

I hope I have at least picked your interest and hopefully will see you in October.

Masterclass: iOS development in Objective C

That’s one pompous title, I admit. But I have no better idea how to call this series of posts I wanted to write for a long time. So let’s add a bit of context to it:

…for non-Computer Science developers.

I’ve been working on ObjC/iOS apps for a very long time, since day 1 of the iPhone SDK. Before that, I was (as it’s now called) front-end developer for 15 years, mostly working in HTML (since 2.0 times baby), witnessed the CSS birth and rise. Been part of the first batch of Javascript developers back in Netscape Navigator 2 then all the way through its rise into plethora of framework abominations “real” (sic!) developers made out of it when they were forced to use it. I did it because I was a designer at first, an UX designer at heart and web was new and exciting canvas for both.

You can see one thing missing from this retrospective. I was never a Computer Science student.