天天看點

swift語言點評二

一、資料類型

1、基礎類型的封裝

Swift provides its own versions of all fundamental C and Objective-C types, including <code>Int</code> for integers, <code>Double</code>and <code>Float</code> for floating-point values

2、新類型

 Swift introduces advanced types not found in Objective-C, such as tuples.

Tuples enable you to create and pass around groupings of values.

3、類型安全語言

Swift is a type-safe language, which means the language helps you to be clear about the types of values your code can work with.

4、資料類型轉化

<code>let three = 3</code>

<code>let pointOneFourOneFiveNine = 0.14159</code>

<code>let pi = Double(three) + pointOneFourOneFiveNine</code>

<code>// pi equals 3.14159, and is inferred to be of type Double</code>

5、Tuples

<code>let http404Error = (404, "Not Found")</code>

<code>let (statusCode, statusMessage) = http404Error</code>

<code>print("The status code is \(statusCode)")</code>

<code>// Prints "The status code is 404"</code>

<code>print("The status message is \(statusMessage)")</code>

<code>// Prints "The status message is Not Found"</code>

6、Optionals

<code>let possibleNumber = "123"</code>

<code>let convertedNumber = Int(possibleNumber)</code>

  類型推斷 convertedNumber:Int?

7、Optional Binding

  if let firstNumber = Int("4")

  You use optional binding to find out whether an optional contains a value

8、Implicitly Unwrapped Optionals

 . You write an implicitly unwrapped optional by placing an exclamation mark (<code>String!</code>) rather than a question mark (<code>String?</code>) after the type that you want to make optional.

------------------越是喧嚣的世界,越需要甯靜的思考------------------

合抱之木,生于毫末;九層之台,起于壘土;千裡之行,始于足下。

積土成山,風雨興焉;積水成淵,蛟龍生焉;積善成德,而神明自得,聖心備焉。故不積跬步,無以至千裡;不積小流,無以成江海。骐骥一躍,不能十步;驽馬十駕,功在不舍。锲而舍之,朽木不折;锲而不舍,金石可镂。蚓無爪牙之利,筋骨之強,上食埃土,下飲黃泉,用心一也。蟹六跪而二螯,非蛇鳝之穴無可寄托者,用心躁也。

繼續閱讀