Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic data types of swift

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the basic data types of swift, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

/ *

-- swift basic data type

OC:

Integer int intValue = 10

Floating point double doubleValue = 10.10; float floatValue = 5.1

Long long

Short short

Signed signed

Unsigned unsigned

The value range of various types of data varies under the compiler of different bits.

Swift: pay attention to keyword capitalization

, /

/ / 1 you can view the type of an identifier through: option + left mouse button

/ / 2 swift has a type inference attribute

/ / Integer

Var intValue:Int = 10

/ / floating point type

Var intValue1:Double = 10.10 / / represents a 64-bit floating point number

Var intValue2:Float = 9.9 / / represents a 32-bit floating point number

/ / if divided by length, the length in Swift is more accurate than that in OC.

Var intValue3:Int8 = 6

Var intValue4:Int16 = 7

Var intValue5:Int32 = 8

Var intValue6:Int64 = 9

/ / signed and unsigned. Default is symbolic (UInt8/UInt16/UInt32/UInt64)

Var uintValue7:UInt = 10

/ / Note: unsigned numbers have a larger range of values than signed ones, because symbolic bits are also used to store values.

/ / Swift is a type-safe language. If you make a value error, it will report an error directly, but OC will not.

/ *

The value is not correct

OC:unsigned int intValue =-10; will not report an error

Swift:var intValue:UInt =-10 will report an error

Overflow:

OC:int intValue = INT_MAX + 1; will not report an error

Swift:var intValue:UInt = UInt.max + 1 will report an error

, /

/ *

Mutual assignment of data types (implicit type conversion)

OC can

Int intValue = 10

Double doubleValue = intValue

Swift: no

Var intValue:Int = 10

Var doubleValue:Double = intValue

The above statement will report an error when "values are never implicitly converted to other types" in Swift (implicit type conversions can be done in OC).

, /

After reading the above, do you have any further understanding of the basic data types of swift? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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: 208

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report