freeCodeCamp/guide/chinese/swift/constants/index.md

23 lines
559 B
Markdown
Raw Normal View History

---
title: Constants
localeTitle: 常量
---
## 常量
常量将名称与特定类型的值相关联。
#### 例:
```swift
let name = "Chris Lattner"
```
使用`let`关键字声明常量然后为其指定`name`然后使用赋值运算符`=`将值`"Chris Lattner"`赋值给常量`name` 。
一旦声明了常量,就不再需要使用`let`关键字了,只需按名称调用它即可。
一旦设定,就不能改变常数的值。
#### 更多信息:
* [Swift编程语言](https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID310)