Swift 基础(一)
2019-06-13 本文已影响0人
CaptainRoy
- 打印
print("Hello, World!") // Hello, World!
- 变量
var name = "Roy"
print("我的名字:\(name)") // 我的名字:Roy
- 常量
let country = "China"
print("我的国际:\(country)") // 我的国际:China
- 整型
var age:Int
age = 18
print("我的年龄:\(age)")
- 浮点型
var doubleValue:Double
doubleValue = 1.68
var floatValue:Float
floatValue = 3.14
- 布尔值
var boolValue:Bool
boolValue = false
boolValue = true
print(boolValue) // true
- 字符串 和 字符
var str:String
str = "1024"
print(str) // 1024
var character:Character
character = "$"
print(character) // $
- 可选
var str:String? = "可选"
if str == nil {
print(str!) // 可选
}
- 元组
let httpError = (404,"Not Found")
let (statusCode,statusMessage) = httpError
print(httpError.0)
print(httpError.1)
print(statusCode)
print(statusMessage)
let httpStatus = (statusCode:404,statusMessage:"Not Found")
print(httpStatus.statusMessage)
print(httpStatus.statusMessage)