Categories
Swift

Swift Common Types of data

Now most of the high-level programming language,All evolved from the classic C language,You grammar which in these programming languages,More or less can be found in the shadow of a fraction of the C language,This is why a lot of people still recommend,From the C programming language into the language of the door。

but,C language is indeed a sufficient old,Many people are directed to write a program target learning to play the APP,You to learn C language ...... sorry,Probably a whole book finished school,You can not write a beautiful beautiful UI interface。

but,anyway,To learn Swift , Or at least you should know some of the most basic knowledge - for example,,With respect to the C language,,Swift is a high-level language。

Digress,In short,In this lesson we want to learn and understand the point of knowledge:Programming language data types。

Because most programming languages ​​from C,Also, because the computer architecture itself so,Therefore, the basic data type is always so few,For example, plastic、For example, floating-point、For example, strings, etc.,This lesson,We turn to interpret these data types to Swift angle。

Plastic Int

In almost all programming languages ​​which have Int shaping the concept of data,In the C language,int probably will occupy 4 bytes in memory of them,That is 4byte = 32bit,In OSX operating system, which is due 64,Then shaping size should be 64bit is 8 bytes。

This is something we can also use sizeof()Function to see。As for the maximum number of how much can be stored,Not discussed here,Strange variety of platforms,In short,You know it can put a large number of goods definitely enough it wants,If it is not enough,There UInt Type, This represents a non-negative plastic,Integer variable memory space in which,Gotta reserved several bit used to mark the number is positive or negative,If you want a larger positive integer,So UInt is a good choice (the bit is also used to mark numbers reserved,This will mark more。) C language which we often encounter such as plastic overflow that experiment ...... this does not happen in Swift among,Because the compiler will check it out。

Shaping,As the name suggests it is used to store an integer,Any number behind the decimal point will be erased,Among the Swift,The compiler does not even accept direct assignment to the orthopedic float。

Float Float

Float is designed to store the type of decimal,Swift reserved only for you six significant digits,For example, this is a:

 

Then a float variable output will eventually be so:

This is the scientific notation,In fact, that is the case:

You see,From left to right back six-figure dropped all the details on it! and so,To avoid a large number plus a small number,This will result in missing details。(Add here,If the language is C, then,The output of the digital detail will exist,Just become all kinds of weird figures Bale。)

Type double Double

So I said I was wayward output is to a large number plus a decimal number,For example, this is:

 

I will output intact! Then double precision may be your favorite:

Double type take up a 64bit value to store,But it includes a decimal,This is also the time to infer the type of Swift decimal preferred type(Note that not Float)If you give a variable initial decimal number such as "0.0" then the compiler will automatically infer that this is a double cargo,This can save you figure it out。

Character Character

Said so much about digital type,Let's talk about character,everybody knows,Every letter we enter,Each text,A string of codes are translated from,And this type of Character,The code is stored in the type of,This unusual,Here we point out that it is to say that the next type。

String type String

String is a string of characters slightly,It is a collection of values ​​of character, for example "Hello World"

In actual use,String is a lot of opportunity to use,For example, to display a list of,name、There synopsis and so on all need a place to display text basically captive String

Array Array

An array is an ordered combination of a series of the same type,It may be a bunch of int ,It may also be a bunch of String ,It all depends on your preferences,Array starts counting from 0,For example, I want an array of eight members,Then the size of the array is 8,However, the first number is a value of 0,The last number is a value of 7,Many people start here confused,To distinguish the relationship between the total number and serial number under the subject between。

字典 Dictionary

Different dictionaries and arrays,It is just to make up the array of defects:Dictionary allows combination of different types of values。But it does not provide a sequence。

So,Dictionary provides a "key" is the key as the tag values。When using a dictionary,Require a predetermined type of dictionary keys and values,Before you can use。

Basically these are the common types of data,With the deepening of the rest of us will continue to explain the course。

Original article written by Gerber drop-off:R0uter's Blog » Swift Common Types of data

Reproduced Please keep the source and description link:https://www.logcg.com/archives/1005.html

By R0uter's Blog

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *