2014年7月31日 星期四

Swift Language Guide - Basic Operators

Swift Language Guide - Basic Operators

Assignment

  • Assignment NOT return a value

      if x = y { <-- Error
      }
    
  • Assignment with Tuple and Swap

      var (x, y) = (1, 2)
      println("(x, y) = (\(x), \(y))")
    
      (x, y) = (y, x)
      println("(x, y) = (\(x), \(y))")
    

Remainder

Support remainder (%) on FLOATING-POINT

println(8 % 3.3)

Ternary

question ? answer1 : answer2

Range

  • Closed Range

      for i in 0...5 {
          println(i)      <-- print 0 ~ 5
      }
    
  • Half-Closed Range

      for i in 0..<5 {
          println(i)
      }
    

P.S. Half-Closed range operator is changed. old .. is NOT USED.

沒有留言: