In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of Swift variables, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Swift is a programming language developed by Apple specifically for OS X and iOS applications. Swift is superior to Objective-C in all respects and doesn't have so many complex symbols and expressions. At the same time, Swift is faster, more convenient, more efficient and safer. In addition, the new Swift language will still be compatible with Object-C.
Each variable in Swift specifies a specific type that determines how much memory the variable takes up, and different data types also determine the range of values that can be stored.
In the previous section, we introduced you to the basic data types, including shaping Int, floating-point Double and Float, Boolean Bool, and string type String. In addition, Swift provides other more powerful data types, Optional, Array, Dictionary, Struct, and Class.
Next we will show you how to declare and use variables in Swift programs.
Variable declaration
Variable declaration means telling the compiler where in memory to create how much storage space for the variable. Before using a variable, you need to declare it using the var keyword, as follows:
Var variableName = (initial value)
The following is a simple example of a variable declaration in a Swift program:
Import Cocoavar varA = 42print (varA) var varB:FloatvarB = 3.14159print (varB)
The execution results of the above procedures are as follows:
423.14159
Variable naming
Variable names can consist of letters, numbers, and underscores.
Variable names need to start with a letter or an underscore.
Swift is a case-sensitive language, so uppercase and lowercase letters are different.
Variable names can also use simple Unicode characters, as shown in the following example:
Import Cocoavar _ var = "Hello, Swift!" print (_ var) var Hello = "Hello World" var Rookie tutorial = "www.runoob.com" print (Hello) print (Rookie tutorial)
The execution results of the above procedures are as follows:
Hello, Swift! Hello, World www.runoob.com.
Variable output
Variables and constants can be output using the print (swift 2 replaces print with println) function.
You can insert variables in a string using parentheses and backslashes, as shown in the following example:
Import Cocoavar name = "" var site = "https://www.yisu.com/"print("\(name) 's official website address is:\ (site)")
The execution results of the above procedures are as follows:
The official website address is: https://www.yisu.com/, thank you for reading this article carefully. I hope the article "sample Analysis of Swift variables" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.