Swift Language-Basic data types

Source: Internet
Author: User
Tags uppercase letter

1. What are the basic data type 1 basic types?

Swift basic data types include integer and floating point type. The base type starts with an uppercase letter. Assigning a value to a type can only be assigned with a numeric value of the same type.

#import Foundation//var intValue = 3.14
2 What are the integral types?

Integral type is divided into signed integral type and unsigned integer type, and integral type can be separated by bit. There are several:
Int8, Int16, Int32, Int64
UInt8, UInt16, UInt32, UInt64

3 What are floating-point types?

Float type, double type

4 How do I use basic data types?

The following code describes how to use the base type.

#import Foundationvar intValue : Int = 8println(intValue)var doubleValue : Double = 8.8println(doubleValue)
5 What are the syntax for different types of conversion assignments?

Two types cannot use the implicit type conversion.
However, you can use forced type conversions. Note that parentheses are given to the variable, not to the type.
The syntax is as follows:
Type 1 Variable value = Type 2 (type 2 variable value)

#import Foundationvar0//var doubleValue = intValuevar doubleValue = Double(intValue)println(doubleValue)
2. How does the implicit type inference 1 work?

The variable type is implicitly set by the initial value of the variable by not writing the type label after the variable. The variable types in the following code are of type int and double type. In Swift, the integer default is the int value, and the float type defaults to the double value.

#import Foundationvar intValue = 0//等价于var intValue : Int = 0println(intValue)var doubleValue = 0.0//等价于var doubleValue : Double = 0.0println(doubleValue)var"swift"//等价于var stringValue : String = "swift"println(stringValue)

Swift Language-Basic data types

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.