swift NO.1

// Playground - noun: a place where people can play

 swift2.2  NO.1

import UIKit

 

var str = "Hello, playground"

// Playground - noun: a place where people can play

//

print("Hello,world")

//

var myVariable=42

myVariable=50

let myConstant=43

//

let implicitInteger=70

let implicitDouble=70.0

或者

let explicitDouble:Double=70

//

let label="The width is "

let width=94

let widthLabel=label+String(width)

//

let apples=3

let oranges=5

let appleSummary="I have \(apples) apples."

let fruitSummary="I have \(oranges) oranges."

///

///

var shoppingList=["catfish","water","tulips","blue paint"]

shoppingList[1]="bottle of water"

var occupations=["Malclm":"Caption","Kalyee":"Mechanic"]

occupations["Jayne"]="Public Relations"

println(occupations["Jayne"])

//

shoppingList=[]

occupations=[:]

//

    let individualScores=[75,43,103,87,12]

    var teamScore=0

    for score in individualScores{

        if score>50{

            teamScore+=4

        }

        else

        {

        teamScore+=1

        }

        }

     println(teamScore)

 

 

//

var optionalstring:String?="Hello "

println(optionalstring == nil)

var optionalName:String?="John Appleseed"

var greeting="Hello!"

if let name = optionalName

{greeting="Hello,\(name)"}

 

//

let nickName:String?=nil

let fullName:String="John Appleased"

let informalGreeting="Hi \(nickName ?? fullName)"

 

////good example

let vegetable = "red pepper"

switch vegetable {

    case "celery":

    println("Add some raisins and make ants on a log.")

    case"cucumber","watercress":

    println("That would make a good tea sandwich.")

case let x where x.hasSuffix("pepper"):

    println("Is it a spicy \(x)?"   )

default:

    println("Everything tastes good in soup.")

}

posted @ 2016-03-01 23:32  yshgxm  阅读(224)  评论(0编辑  收藏  举报