News for hackers. Stuff that matters.
Re:Swift 1.2 and Xcode 6.3 beta by LinaLauneBaer on Monday February 09, 2015 @02:35PM (#9023155)
often times you want to do more stuff in either case so ? does not always work. The if-else approach is more general.
Re:Swift 1.2 and Xcode 6.3 beta by matt_kantor on Monday February 09, 2015 @03:07PM (#9023332)
You could also do this:

    let x: Something = {
      if condition {
        someSideEffect()
        return foo()
      } else {
        anotherSideEffect()
        return bar()
      }
    }()
But it's kind of ugly.
Re:Swift 1.2 and Xcode 6.3 beta by masklinn on Monday February 09, 2015 @03:31PM (#9023489)
Sad that Swift doesn't use an expressive if, then you could just write:

    let x: Something = if condition {
        // do stuff
        foo()
    } else {
        // do other stuff
        bar()
    }
Re:Swift 1.2 and Xcode 6.3 beta by 0942v8653 on Monday February 09, 2015 @10:03PM (#9025155)
That's something I really miss in other languages—the ternary operator is just not good enough for when you have a condition like this. In lisp it's 3 lines which is just the right amount when in other languages you have 6 lines (and until now unnecessary mutability) or only one.