Swift: New stuff in Xcode 7 Beta 3

Beta beta if you can. Don’t catch me! He’s the muffin man. Enum with me to a land of of pure enumeration. We’ll begin with a spin, traveling to string types of my creation. — Failed post titles.

Here’s a few things that caught my eye in today’s beta.

Default Enum Naming. New to beta 3, string enums without explicit raw values default to the text of the enum’s name. This is tremendous and I love it to pieces. It’s the one really big news item for this beta, so take a look.

Screen Shot 2015-07-08 at 6.56.45 PM

 

Explicit Label Exclusion. Have you had any issues with functions getting confused between arguments and tuples? Confuse no more. Unnamed parameters now require an explicit _ to differentiate between func f((x: Double, y: Double)) and f(x:Double, y:Double). Use func f(_ point: (Double, Double)).

Arruples. You can now add tuples to arrays. They work even though they appear to error.

Screen Shot 2015-07-08 at 7.01.00 PM

ObjC Generics. Objective-C classes now support generic subclasses. I haven’t had time to really kick the wheels on this one yet. Nor have I tried the NS_REFINED_FOR_SWIFT macro that lets you create Swift-specific enhanced implementations in addition to less able Objective-C ones.

Dot-Com(mands). The lines of dot-doom that extend forever and make code folding such a pain are addressed in Beta 3. Lines starting with periods, as in the following example, parse as conjoined  methods and properties that extend the previous line.

let values = split("Lorem ispum eejit".characters,
    isSeparator:{$0 == Character(" ")})
    .map({String($0)})
    .map({"item \($0)"})
    .count

The side effect of this change according to the release docs is that you can no longer start lines with inferred static member lookup, so .staticVar = value is out. Since I can’t remember ever using this form for, well, anything, I’m not terribly concerned.

 

5 Comments

  • Thanks for the review. I’m not sure about the dot thing though. How is it different from 1.2? I tried breaking a composite expression with dots over a couple of lines, and with the dot to the left of the right hand part XCode was fine with it.

    • There are a few cases where it wouldn’t work – like if you chained a bunch of functions, a property on the next line wouldn’t work:

      [1, 2, 3, 4, 5]
      .filter { $0 % 2 == 0 }
      .map { $0 * 2 }
      .count // breaks

      [1, 2, 3, 4, 5]
      .filter { $0 % 2 == 0 }
      .map { $0 * 2 }.count // works

      • Good, then. It seems that the new release makes the syntax more consistent and predictable.

  • Oh, you are just a heroic human being. I was beating my head against a problem for the last few hours because I didn’t realize beta 3 changed how Enums work. Read this and now it is smooth sailing. Thanks!

  • Thank you for pointing out the newness in Beta 3, Erica.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>