Swift Basic Syntax (01-Constants and variables)

Source: Internet
Author: User

  Learn Swift First step print Hello worldPrint ("Hello World") Swift is not semicolon-delimited What is a constant?Constants are the amount of values that cannot be changed during a program's operation what time variable?Variables are the amount of changes that can be made during a program's operation. Constants and variables must be declared before use in Swift letTo declare constants, use the varTo declare a variable constants are defined in the following way:You can use any character you like as a constant and variable name, including Unicode character constants and variable names that cannot contain the following: mathematical symbols, arrows, reserved (or illegal) Unicode code points, lines and tabs. You cannot start with a number, but you can include a number elsewhere in a constant and variable name. Note: Constants in Swift must be initialized at the time of definition (OC can be uninitialized), otherwise error let Max =10let?? = 100 How variables are defined:define re-initialization ———— > (OC notation below) in OCint age;age = 10; You can also define the simultaneous initialization of int age = 10;in Swift, first define reinitialization:The Var age is a direct error. Cause of error: (Type annotation missing in pattern: No data type specified) in Swift if you want to define a variable first, you must tell the compiler variable's type when you use it at the time of definition ( Type callout): var age:intage = 20 Simultaneous initialization of the definition: If a variable is initialized at the same time as defined in swift, the type of the variable can be inferred automatically based on the initialized value (type inference mechanism) var age:int = 20var Age = 20

Swift Basic Syntax (01-Constants and variables)

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.