简单值(Simple Values)

2015-10-27  本文已影响29人  ChiOS

1.其他类型转化为字符串

let label ="The width is"

let width =94

let widthLabel = label +String(width)

String(width) -> [NSString stringWithFormat:@"%@", width]


2.控制流

letvegetable ="red pepper"

switch vegetable {

case"celery":

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

case"cucumber","watercress":

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

case le tx where x.hasSuffix("pepper"):

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

default:

  print("Everything tastes good in soup.")}

switch支持任意类型的数据以及各种比较操作——不仅仅是整数以及测试相等。

不用break?

上一篇 下一篇

猜你喜欢

热点阅读