Swift Basic Syntax (02-Basic data type)

Source: Internet
Author: User

Basic data TypesOc:
integer int intvalue = 10;
Floating-point double doublevalue = 10.10; float Floatvalue = 5.1;
Chang Long
Short
Signed signed
Unsigned unsigned the range of values for various types of data is different from the compiler for different bits. Swift: note keyword uppercase integer var intvalue:int = 10 floating-point var intvalue1:double = 10.10 means 64-bit floating-point Var Intvalue2:float = 9.9 means 32-bit floating-point number if the length is divided, the length of Swift is more accurate than oc var intvalue3:int8 = 6
var intvalue4:int16 = 7
var Intvalue5:int32 = 8var Intvalue6:int64 = 9 signed unsigned, default is signed (Uint8/uint16/uint32/uint64) var uintvalue7:uint = 10 Note: unsigned The number is greater than the signed value, because the symbol bit is also used to store the value Swift is a type-safe language, if the value error will be directly an incorrect, and OC will not take the value of oc:unsigned int intvalue =-10; No error Swift:var Intvalue:uint = 10 will error overflow: oc:int intvalue = Int_max + 1;  No error Swift:var Intvalue:uint = Uint.max + 1 Error data type reciprocal assignment (implicit type conversion) OC can implicitly type convert int intvalue = 10;double Doublevalue = intvalue; Swift: No implicit type conversion in Swift "value is never implicitly converted to another type" (an implicit type conversion in OC) The following statement will error var intvalue:int = 10var doublevalue:double = intvalue data type conversions Swift does not allow implicit type conversions, but can use display type conversions (coercion type conversions) OC notation int intvalue = 10;double Doublevalue = (double) intvalue; Swift notation: var intvalue:int = 10
var doublevalue:doubledoublevalue = double (intvalue) Note: double () does not modify the value of Intvalue Instead, it generates a temporary value assignment to Doublevalueprint (intvalue) print (doublevalue) by Intvalue value.

Swift Basic Syntax (02-Basic data type)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.