Xcode 6.3: Wheeeee! Beta threeeeee!

As far as I’m concerned, the biggest changes here have to do with playgrounds, which I’ll discuss shortly. However, there’s one new language feature that’s gotten me all happy and excited. flatMap (which I keep calling “flapMat” — perhaps it will catch on), will map a function over Arrays ( ArraySlice/ContiguousArray) and optionals and return flattened results.

With normal map, you apply a closure across each element.

var x = [["a", "b", "c"], ["d", "e"], ["f", "g", "h"]]
println(x.map{count($0)}) // returns [3, 2, 3]

But flat map goes an extra step. It applies map and then flatten. In its most simple state, you can de-array elements inside.

println(x.flatMap {$0}) // returns [a, b, c, d, e, f, g, h]

Or you can tweak the items a little, etc.

println(x.flatMap {$0 + ["XX"]}) // returns [a, b, c, XX, d, e, XX, f, g, h, XX]

Kevin Ballard tells me this is also great for “When you have an optional and want to run an expression that returns an optional and flatten it, just like the ?. chaining operator, but the expression isn’t one that can be chained“. Here’s an example:

var optionalArray: [Int?] = [5, nil, 3, nil, 4, 6, 7, nil, nil, 8]
println(optionalArray.flatMap {(x : Int?) -> [Int] in
    return x == nil ? [] : [x!]
}) // returns [5, 3, 4, 6, 7, 8]


Today’s other big changes have to do with Playgrounds. The file navigator now automatically includes two folders, one for Resources (you don’t have to edit bundles or use the “go to folder” arrow in the File inspector), the other for additional sources, so  you can declutter your playground and focus on getting things done.

Screen Shot 2015-03-12 at 12.00.44 PM


It took me all of about 2 seconds to add a new BezierPolygon.swift file so I could add custom QuickLook previews to a Bezier shape class. (Click the following to see the full-size screen shot).

Screen Shot 2015-03-12 at 12.03.53 PMYou do have to treat each file as if it’s part of a module. Make sure to use public liberally to expose elements to the playground.

Other quick items:

  • You can now upgrade playgrounds so you can use rich text formatting without having to create new documents and then copy/paste. Use Editor > Upgrade Playground
  • Rich text markup using standard Apple markup is no longer as crappy as it was in the previous beta.”Using the “/*: */ multi-line variant of Playgrounds rich comment markers no longer results in the comment block being duplicated further down in the document. (19917362)”
  • The playground is overall not as crashy crashy as in beta 2 due to stability enhancements.


Comments are closed.