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)