转载链接:http://www.cocoachina.com/newbie/basic/2014/0604/8675.html
备忘录:http://www.cocoachina.com/applenews/devnews/2014/0604/8663.html
1. SWift我来了,hello world!
- println("hello, world")
- var myVariable = 42
- myVariable = 50
- let myConstant = 42
- let implicitInteger = 70
- let implicitDouble = 70.0
- let explicitDouble: Double = 70
- let width = 30
- let widthLable = "The width is \(width)"
- let widthLabel1 = "The width is" + String(width)
- let widthLable2 = "Phone" + " width is \(width)"
- var shoppingList = ["catfish", "water", "tulips", "blue paint"]
- shoppingList[1] = "bottle of water"
- var occupations = [
- "key1": "value1",
- ]
- occupations["key2"] = "value2"
- occupations["key1"] = "value111"
- let emptyArray = String[]()
- let emptyDictionary = Dictionary<String, Float>()
- let vegetable = "red pepper"
- switch vegetable {
- case "celery":
- let vegetableComment = "Add some raisins and make ants on a log."
- case "cucumber", "watercress":
- let vegetableComment = "That would make a good tea sandwich."
- case let x where x.hasSuffix("pepper"):
- let vegetableComment = "Is it a spicy \(x)?"
- default:
- let vegetableComment = "Everything tastes good in soup."
- }
- let n = 2
- switch n {
- case 1:
- println("It's 1!")
- case 2...4:
- println("It's between 2 and 4!")
-
case 2..4:
-
println("It's between 2 and 3!")
- case 5, 6:
- println("It's 5 or 6")
- default:
- println("Its another number!")
- }
- func greet(name: String, day: String) -> String {
- return "Hello \(name), today is \(day)."
- }
- greet("Bob", "Tuesday")