加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift简单的赋值

发布时间:2020-12-14 02:04:10 所属栏目:百科 来源:网络整理
导读://: Playground - noun: a place where people can play import UIKit var str = "Hello,playground" var myVar = 45 myVar = 90 let myCon = 90 let implictInteger = 70 let implicitDouble = 80.0 let explicitDouble: Double = 700 let expFloat: Float

//: Playground - noun: a place where people can play


import UIKit


var str = "Hello,playground"

var myVar = 45

myVar = 90

let myCon = 90


let implictInteger = 70


let implicitDouble = 80.0


let explicitDouble: Double = 700


let expFloat: Float = 4

//值永远不会隐式转换为另一种类型。如果你需要把一个值转换到不同类型,需要明确的构造一个所需类型的实例。

let label = "The width is "


let width = 100


let widthLabel = label + String(width)

//实现字符串中包含值:以小括号来写值,并用反斜线()放在小括号之前

let apples = 3


let oranges = 5


let appleSummary = "I have (apples) apples."


let fruitSummary = "I have (apples + oranges) pieces"


let impdouble = 90.0


let tom = "name"


let labe = "go to (impdouble) (tom) fname"

//创建一个数组和字典使用方括号"[]",访问其元素则是通过方括号中得索引或键。

var shoppingList = ["catish","water","tulips","blue paint"]


shoppingList[1] = "bottle of water"


var occupations = [

"Malcolm": "Captain",

"Kaylee": "Mechanic",

]

occupations["Jayne"] = "Public Re"

//创建一个空得数组或字典,使用初始化语法:

let emptyArray = [String]()


let emptyDictionary = Dictionary<String,Float>()

//如果类型信息无法推断,你可以写空的数组"[]" 和空的字典"[:]",例如你设置一个知道变量并传入参数到函数:

shoppingList = []

occupations = [:]

//数字字面量(Literals)

var decimalInteger = 17//十进制

var binarryInteger = 0b10001//二进制

let octalInteger = 0o21//八进制

let hexadecimalInteger = 0x11//十六进制

//可选值绑定

var temp1: String? = "123"

if let temp2 = temp1?.toInt() {

println("(temp1) has an (temp2)")

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读