Chapter 2: Variables and Constants

*In Swift, you can optionally use underscored to make larger numbers more human-readable. The quantity and placement of the underscores is up to you.


*Swift is very strict about the types it uses and won't let you assign a value of one type to a variable of another type. Instead of simply assigning, you need to explicitly say that you want to convert the type.

var integer: Int = 100

var decimal: Double = 12.5

integer = Int(decimal)

 

*A tuple is a type that represents data composed of more than one value of any type.

If you want to ignore a certain element of the tuple, you can replace the corresponding part of the declaration with an underscore. 

let (x2, y2, _) = coordinates3D


*Sometimes it's useful to check the inferred type of a variable or constant. You can do this in a playground by holding down the Option key and clicking on the variable or constant's name.


*Type inference allows you to omit the type when Swift already knows it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值