ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## Introducing to Swift * Playground 是自 Xcode6 起苹果加入的实时浏览代码结果的一个功能。 * 变量通过 var 声明,常量通过 let 声明。 Swift 可以推断变量的类型(type reference),所以声明变量可以直接如下: ~~~ var string = “My string” //也可以先声明类型(必须)或声明与赋值同时: var string:String = “My string” ~~~ * 苹果官方建议在声明有小数部分的变量时都采用 Double,因其具有更高的精准度。 * Swift 中 bool 值是 true 和 false。 * “+” 号也可用于 string : ~~~ var name1 = "Tim McGraw" var name2 = "Romeo" var both = name1 + " and " + name2 //"Tim McGraw and Romeo" ~~~ * 字符串的对比运算是”case-sensitive”,也就是区分大小写: ~~~ var name = “TIM MCGRAW" var name2 = "TiM mCgRaW" name == name2 //result is false ~~~ * 在 string 中插入变量: ~~~ var name = “Tim McGraw” “Your name is \(name)” //可以在括号中运算: var age = 25 “His age is \(age * 2)” ~~~