Swift (i)

Source: Internet
Author: User

Directly on the code:
  //Output functionprintln"Hello World")/Let define constant var define variable         LetLogincount= 5        varCurrentlogincount= 0//Logincount = 10//Burst red//Currentlogincount =println ((Logincount, Currentlogincount))//Remove parenthesis Error        //define multiple constants or variables in the same row         LetA= 1B= 2C= 3        varX= 4Y= 5Z= 6        varStr1= "STR1", str2= "STR2", STR3= "STR3"        //Type callout        //declares a variable of type String named Namestring        varNamestring:StringNamestring= "Cacaca"println ((namestring))//Let Count:int//for Xcode 6.3 and above//Count =//println ((count))        //variables, names of constants         LetWang= "high-rich handsome"        var??= "?"        //variables or constants cannot start with a number, but numbers can be placed in the middle or at the end         LetA2b2= 123;        println ((??)) println (Wang)//Output constants and variables        //Use the string difference to add the current variable name as a placeholder to the string, and then add parentheses and backslashes to transfer the output.         varJuicename= "Apple Juice"println ((juicename)) println (("I love \" (juicename)))varIosdevice= "IPhone6"println"I want to \ (Iosdevice) ぁゅゐ??")//Notes        //single-line comment        / * Multiline Comment * /        / * This is the beginning of the first multiline comment/* This is the beginning of the second multiline comment * /This is the end of the second multi-line comment, which is the end of the first multiline comment*/        //You must add a semicolon behind the statement        You need to add a semicolon when you need to add multiple independent statements in a row        var??= "Rubbit"; println (??) Letadb= Ten; println ((ADB));///8-bit signed integer type the minimum maximum value that can be represented         LetMinInt8=Int8.min         LetMaxInt8=Int8.Maxprintln ((MinInt8, maxInt8))///8-bit unsigned integer type can represent the maximum minimum value         LetMinUint8=UInt8.min         LetMaxUint8=UInt8.Maxprintln ((MinUint8, maxUint8))//16-bit signed integer type can represent the maximum minimum value         LetMinInt16=Int16.min         LetMaxInt16=Int16.Maxprintln ((minInt16, maxInt16))///16-bit unsigned integer type can represent the maximum minimum value         LetMinUint16=UInt16.min         LetMaxUint16=UInt16.Maxprintln ((minUint16, maxUint16))//32-bit signed integer type can represent the maximum minimum value         LetMinInt32=Int32.min         LetMaxInt32=Int32.Maxprintln ((MinInt32, MaxInt32))///32-bit unsigned integer type can represent the maximum minimum value         LetMinUint32=UInt32.min         LetMaxUint32=UInt32.Maxprintln ((MinUint32, MaxUint32))//64-bit signed integer type can represent the maximum minimum value         LetMinInt64=Int64.min         LetMaxInt64=Int64.Maxprintln ((MinInt64, MaxInt64))///64-bit unsigned integer type can represent the maximum minimum value         LetMinUint64=UInt64.min         LetMaxUint64=UInt64.Maxprintln ((MinUint64, MaxUint64))//Float accurate to 5 digits after decimal point        varπ:floatπ= 3.1415926println ((π))//double accurate to 14 digits after decimal point        varPi1:D oubleπ1 = 3.1415926535897932384println (π1))//Type safety        varStr= "IPhone"        //The system will automatically infer that STR is a String type        //Type safety, the top system is inferred as a String, the bottom of the assignment of other types, the compiler will directly error.         //str = 10;//compiler will burst red hint str is a String type,        varValue= Ten        //The system is automatically inferred as Int//value = "AGLKHELKHG" At the time of assignment the system will first type inference, the system is inferred to be an Int type, the bottom of the assignment is a String, the compiler will directly error, the hint type mismatch.          LetPdsu= 5 + 1.442        //The system will automatically infer the Double type        //numeric type conversions         LetValue1:uint16= 3200         LetValue2:uint8= 7        ///Two different numeric types cannot be added directly because the type does not match//Let Value3 = value1 + value2        //You need to convert a numeric type to the same type for other operations         LetValue3=Value1+UInt16 (value2) println ((VALUE3))varOne=  - //Type inferred to be of type Int        varBoth= 3.13  //Type inference to Double type        varThree=Double (one)+println ((three))//Type aliases        //Give a more meaningful name to the existing typeTypealias Audiosample=Int LetMaxValue=Audiosample.Maxprintln (MaxValue)//bool type, type will trigger type inference, inferred as bool type         LetAreyouok= true         LetAreyoulikeshit= false        ifAreyouok {println ((Areyouok))}if !Areyoulikeshit {println ((areyoulikeshit))}//Tuple         LetHttp404error=(404,"Not Found!")access to//meta-group data         Let(Messagecode, message)=Http404error println ("This is status code \ (Messagecode)") println ("This is status message \ (message)")//access by subscriptprintln"This is status code \ (http404error.0)") println ("This is status message \ (Http404error.1)")//If you only need a subset of the value of the tuple, you can break down the part you want to use _ Mark         Let(Justneedstatuscode, _)=Http404error println ("This is status code \ (Justneedstatuscode)") Let(_, Justneedstatusmessage)=Http404error println ("This is status message \ (justneedstatusmessage)")//You can name a single element when you define a tuple         LetHttp200status=(StatusCode: $, Message:"OK") println ("This is status code \ (Http200status.statuscode)") println ("This is status message \ (http200status.message)")//Optional type         LetPossablenumber= "123"         LetConvernumber=Possablenumber.ToInt ()//CONVERNUMEBR is inferred as "Int?" Or a Optional Int .        if  LetNumber=Possablenumber.ToInt () {println ("\ (possablenumber) has an integer value of \ (number)")        }Else{println ("\ (Possablenumber) could not convered integer")        }//Assertion         LetAge= -3ASSERT (age>= 0,"A person's age cound not being less than zero")

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Swift (i)

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.