swift--Type Conversion Basics

Source: Internet
Author: User

Articles for their own study, the department is reproduced. Notes for learning 51cto courses. If there is infringement, please private messages I delete.

The links are as follows.

? http://edu.51cto.com/roadmap/view/id-58.html

1 varStrvalue:string ="12345"2 varIntValue1 = Strvalue.toint ()//to int method so that you can directly convert the3 println (intValue1);4 varIntvalue2:int? = Strvalue.toint ()//An error occurs without a question mark, which turns the intValue2 into an optional state. 5 println (intValue2);6 7 varStrvalue1:string ="AB12"8IntValue1 =Strvalue1.toint ()9println (intValue1);

If it contains non-numeric characters, it returns nil. This is the function of the question mark. Or do not add: int, the system automatically recognizes the type.

1 var strvalue2:string = toString (intValue1);

2 var strvalue3:string = toString (true)

3 println (STRVALUE3) //output is true

swift--Type Conversion Basics

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.