Swift is the development language that Apple released on June 2, 2014, starting with XCODE6 to support the Swift language
is a strongly typed language, where the strong type contains two meanings: 1 All variables must be declared and used, and 2 of variables of the specified type can only accept values that match the type. Strongly typed languages can detect source code errors during compilation, thus ensuring a more robust program
is an object-oriented, compiler-based language
Swift does not require a semicolon at the end of each execution statement
Swift also supports process-oriented programming with the same class and method levels
Swift Program Entry
There are two scenarios: 1 only one source program 2 has multiple source programs
1 when a swift application has only one source program, the first executable code of the file is the portal of the SWIFT program.
2 When Swift application has many source programs, only the source program with file name Main.swift can place executable code, the first line of executable code is the portal of Swift program, other source program can only define classes and functions, etc.
Use the terminal window to compile and run the SWIFT program
Create a Helloworld.swift file and compile it in the terminal program
Swiftc-o Hello.out Helloworld.swift
Hello.out is the compilation of the generated file, which is an executable file
Run the executable file
./hello.out
Which./is to tell the system in the current
If you want to compile multiple source programs into a single file
Swiftc-o hello.out Test.swift Main.swift
Comment Method
Single-line Comment
Comment Content
Multi-line comments
/*
Comment Content
Comment Content
*/
Separator
1 semicolon;
Swift does not require each statement to end with a semicolon, but it can also do so
Swift Each statement can be cross-line, the calling function can cross the line, the call property can not cross the line
When there are more than one statement in a row, you need to separate them with semicolons
2 curly Braces {}
Define a block of code, such as classes, structs, enumerations, functions
3 square brackets []
Used to access arrays and dictionaries, to set the index of an array element that you want to access or a key for a dictionary element
4 parenthesis ()
When defining a function, parentheses are used to include all formal parameter declarations, and the function must be called with parentheses to pass in the parameter values
5 spaces
Spaces can appear anywhere in the SWIFT program
6 dots.
A dot is usually used as a class, struct, enumeration, instance to invoke a property or method
Naming rules
Swift language case-sensitive
Cannot start with a number
Composed of characters, numbers, underscores, and $
swift--Introduction