In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shares with you the content of a sample analysis of Swift constants. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Swift, an open source programming language that supports multiple programming paradigms and compilation, was released by Apple in 2014 at the WWDC (Apple developer Conference) for the development of iOS,OS X and watchOS applications.
Once a constant is set, its value cannot be changed while the program is running.
Constants can be any data type such as integer constant, floating point constant, character constant, or string constant. There are also constants for enumerated types:
Constants are similar to variables, except that the value of a constant cannot be changed once it is set, while the value of a variable can be changed at will.
Constant declaration
Constants are declared using the keyword let. The syntax is as follows:
Let constantName = (initial value)
The following is an example of using constants in a simple Swift program:
Import Cocoalet constA = 42print (constA)
The execution results of the above procedures are as follows:
forty-two
Type annotation
When you declare a constant or variable, you can add a type annotation to indicate the type of value to be stored in the constant or variable. If you want to add a type annotation, you need to add a colon and space after the constant or variable name, and then add the type name.
Var constantName:= (optional initial value)
The following is a simple example of the use of type annotations for constants in Swift. It is important to note that when a constant is defined, it must have an initial value:
Import Cocoalet constA = 42print (constA) let constB:Float = 3.14159print (constB)
The execution results of the above procedures are as follows:
423.14159
Constant naming
The naming of constants can consist of letters, numbers, and underscores.
Constants need to start with a letter or an underscore.
Swift is a case-sensitive language, so uppercase and lowercase letters are different.
Constant names can also use simple Unicode characters, as shown in the following example:
Import Cocoalet _ const = "Hello, Swift!" print (_ const) let Hello = "Hello World" print (Hello)
The execution results of the above procedures are as follows:
Hello, Swift! Hello, World.
Constant output
Variables and constants can be output using the print (swift 2 replaces print with println) function.
You can insert constants in a string using parentheses and backslashes, as shown in the following example:
Import Cocoalet name = "this is how Linux should learn" let site = "the official website address of https://www.linuxprobe.com"print("\(name) is:\ (site)")
The execution results of the above procedures are as follows:
This is how Linux should learn from the official website address: https://www.linuxprobe.com thank you for reading! This is the end of this article on "sample Analysis of Swift constants". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.