1.其他類型轉(zhuǎn)化為字符串
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支持任意類型的數(shù)據(jù)以及各種比較操作——不僅僅是整數(shù)以及測試相等。
不用break?