The national day’s holidays are over,WTF!

Anyway I enjoyed some sweet moment with my family.

I will never, you know, never  gonna try a new thing after it appeared, published or launched immediately, I always been watching at that for a period of time, especially for a new programming language. So I’ve been watching on Swift for a while too.

It seems like a mixture of scripts than a new language,  I can find lots of syntaxes those I saw  from other languages, like javascript, actionscript, or we can say, ECMAScript, Ruby, of course Objective-C.

Even thought it is so friendly to me, it still contains some new features, some of them are really smart, some are odd, I will record them all tentatively.

  • Assigning array items type by syntax:

    var array:[String] = ["A","B"]
  • Add new items to array by operator “+=”, Cool!

    var arrayNumber:[Int] = [1,2,3,4]
    arrayNumber += [9,10] // println [1,2,3,4,9,10]
  • If you don’t assign collection type to a variable, you CAN NOT invoke it’s functions,eg:

    var arr = []
    arr.append("A") 
    // will case an error,because Swift is not sure it is a Dictionary or an Array
    var arr:Array = []
    arr.append("A") 
    //Now it works.
  • The most compact way to declare a integer range from 1 to 100

    let arrayInt = 1...100
    
    

for i in arrayInt {
println(i)
}
BTW, I love the way Swift did on for loop with range.

  • Power features of switch, use range in  case
    var languagesICan:[String] = ["ActionScript","Objective-C","Swift","C","Java","Lua","JavaScript"]
    for var i = 0; i < languagesICan.count ;i++ {
      switch i{
          case 0...1:
              println("I am good at \(languagesICan[i])")
          case 2:
              println("I love \(languagesICan[i])")
          default:
              println("I can program with \(languagesICan[i])")
      }
    }