swift 学习记录(四)
来源:互联网 发布:淘宝网店运营培训班 编辑:程序博客网 时间:2024/06/11 13:37
//练习一
var explicitFloat:Float = 50
print(explicitFloat)
//练习二
var implicitFloat = 20.0
print("Hello Jim ,I geive you \(implicitFloat) money")
//标记:在if 语句中,条件必须是一个布尔表达式——这意味着像if score { ... } 这样的代码将报错,而不会隐形地
//与 0 做对比。
//可选类型
var optionalString: String?
print(optionalString == nil)//说明默认的是nil
var optionalString1: String? = ""
print(optionalString1 == nil)//说明""也是占内存的,与nil不同
var optionalString2: String? = "nil"
print(optionalString2 == nil)//说明"nil"是个字符串,与nil不同
var optionalString3: String? = "Hello World"
print(optionalString3 == nil)//说明optionalString3有值
//switch
//运行switch 中匹配到的子句之后,程序会退出switch 语句,并不会继续向下运行,所以不需要在每个子句结尾
//写break 。
let vegetable = "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 let x where x.hasSuffix("pepper"):
print("Is it a spicy \(x)?")
default:
print("Everything tastes good in soup.")
}//删除default报错:error: switch must be exhaustive, consider adding a default clause,default不能省略
var explicitFloat:Float = 50
print(explicitFloat)
//练习二
var implicitFloat = 20.0
print("Hello Jim ,I geive you \(implicitFloat) money")
//标记:在if 语句中,条件必须是一个布尔表达式——这意味着像if score { ... } 这样的代码将报错,而不会隐形地
//与 0 做对比。
//可选类型
var optionalString: String?
print(optionalString == nil)//说明默认的是nil
var optionalString1: String? = ""
print(optionalString1 == nil)//说明""也是占内存的,与nil不同
var optionalString2: String? = "nil"
print(optionalString2 == nil)//说明"nil"是个字符串,与nil不同
var optionalString3: String? = "Hello World"
print(optionalString3 == nil)//说明optionalString3有值
//switch
//运行switch 中匹配到的子句之后,程序会退出switch 语句,并不会继续向下运行,所以不需要在每个子句结尾
//写break 。
let vegetable = "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 let x where x.hasSuffix("pepper"):
print("Is it a spicy \(x)?")
default:
print("Everything tastes good in soup.")
}//删除default报错:error: switch must be exhaustive, consider adding a default clause,default不能省略
0 0
- swift 学习记录(四)
- swift学习记录(开端)
- swift学习记录(Optional)
- swift学习记录(switch)
- swift学习记录(for)
- swift学习记录(func)
- 操作 swift学习记录(-)
- swift学习记录(selector)
- swift学习记录(in)
- swift 学习记录(一)
- swift 学习记录(二)
- swift 学习记录(三)
- swift学习记录(String)
- swift学习记录(函数)
- swift学习记录(枚举)
- swift 学习记录(继承)
- swift学习记录(析构器)
- swift学习记录(扩展)
- mongo客户端mongo VUE增删改查
- Codevs_P3269 混合背包
- linux下 mysql 忘记密码解决方案
- 关于NSNotificationCenter监听并且传递数据
- SpringIoC依赖注入的过程(二)
- swift 学习记录(四)
- 观点的不同
- 数据库中文问题
- 使用 jdbc 连接 mysql 数据库
- 查看程序的启动参数,入口参数
- PostgreSQL 9.2.4所有命令的语法帮助及SQL语句简要说明
- 排序(插入,堆排序,归并)
- RelativeLayout相对布局
- 详解FCM算法原理及应用