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