首页 > 编程语言 > 详细

swift2.2 NO.1

时间:2016-03-02 00:24:12      阅读:209      评论:0      收藏:0      [点我收藏+]

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

 

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.")

}

swift2.2 NO.1

原文:http://www.cnblogs.com/yshgxm/p/5233325.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!