changjiashuai's blog

Runnig...

The future belongs to those who believe in the beauty of their dreams.


Swift基础---常量、变量

常量声明 (不可变)

let constants = 10
constants = 20 ----> error

变量声明 (可变)

var x = 0
var a = 1, b = 2, c = 3
x = 10

注释类型声明(Type Annotations)

var welcomeMessage: String

任何字符都可以作为变量、常量名

let π = 3.14159
let 你好 = "你好世界"
let 🐶🐮 = "dogcow”

输出常量、变量

println(x)
println(constants) 
最近的文章

Swift基础---Booleans

初始化let orangesAreOrange = truelet turnipsAreDelicious = false 使用if turnipsAreDelicious { println("Mmm, tasty turnips!")}else{ println("Eww, turnips are horrible.")}let i = 1if i { // ---error}if i== 1 { // ---successfully}…

继续阅读
更早的文章

Swift体验2

控制流使用if和switch做条件判断,使用for-in,for,while,do-while做循环操作。括号中的条件或循环变量是可选的。括号的身体是必需的。let individualScores = [75, 43, 103, 87, 12]var teamScore = 0for score in individualScores{ if score > 50{ teamScore += 3 }else{ teamScore +=1 }}teamScore在i...…

继续阅读