The constants and variables of Swift learning

Source: Internet
Author: User

Constant: is at the time of initialization (try to define the value will not be assigned to error) to give an accurate value, can be used in many places directly, with the Let keyword life

Variables: This is needless to say, you can change the amount in the next second, with the VAR keyword declaration

Let width = 94 constant declaration, the data type can not be declared in swift, Swift infers the type itself, or it can declare its own label type, add colon after the name, plus the type to be declared, such as allow explictfloat:float = 4.0 (in order to declare the specification, preferably a space after the colon)
There is no implicit conversion in swift, to convert a data type to another data type, you have to do an explicit conversion, otherwise you will get an error, such as you can remove the following string () Try reading the newspaper what error

Let label = "the width is"
Let width = 94
Let Widthlabel = label + String (width)

There is also an easier way to convert a value to a string, that is, to write a value in parentheses, and then precede the parentheses with a backslash (backslash), for example

Let apples = 5
Let applesummary = "I has \ (apples) apples"

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The constants and variables of Swift learning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.