Do you need help on a specific subject? Use the contact form (Request a blog entry) on the right hand side.


Do not use type inference for dictionaries and arrays

Does xcode (6.1.1) seem to hang? does compilation seem to take forever? You might be a victim of type inference.
While writing a unit test I noticed that the more testcases I added to an array, the slower compilation was. It seemed that indexing was taking forever and that this caused the slowdown in compilation.
A bug in xcode?
A bit of searching learned that type inference can cause this kind of slowdown. Especially when default values are assigned to a large array or dictionary.
Since I defined test strings and test results in an array...

Luckily the solution is simple: avoid type inference by defining the array (or dictionary) explicitly:

Don't do this:

let arr = [[1,2,3,4],[5,6,7,8]]

But do this:

let arr: [[Int]] = [[1,2,3,4],[5,6,7,8]]

Compilation speed (indexing) is now back to normal.

Happy Coding ...

Did this help?, then please help out a small independent.
If you decide that you want to make a small donation, you can do so by clicking this
link: a cup of coffee ($2) or use the popup on the right hand side for different amounts.
Payments will be processed by PayPal, receiver will be sales at balancingrock dot nl
Bitcoins will be gladly accepted at: 1GacSREBxPy1yskLMc9de2nofNv2SNdwqH

We don't get the world we wish for... we get the world we pay for.

No comments:

Post a Comment