<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## ENUMERATION - 枚舉(Enum)可以將一系列相關的值定義為一個組類型,通過如下語法創建 enum: ~~~ enum WeatherType { case Sun, Cloud, Rain, Wind, Snow } ~~~ 下面看看如何使用枚舉類型: ~~~ func getHaterStatus(weather: WeatherType) -> String? { if weather == WeatherType.Sun { return nil } else { return "Hate" } } getHaterStatus(WeatherType.Cloud) ~~~ 也可以這么定義枚舉: ~~~ enum WeatherType { case Sun case Cloud case Rain case Wind case Snow } ~~~ 也可以這么使用枚舉: ~~~ func getHaterStatus(weather: WeatherType) -> String? { if weather == .Sun { return nil } else { return "Hate" } } //Swift 通過 Type inference 知道你與 WeatherType 類型比較,所以無需寫明枚舉類型,但是這種寫法 Swift 將不會提供代碼補足建議輔助 getHaterStatus(.Cloud) ~~~ 枚舉在 switch/case 中十分有用,因為 Swfit 知道你的枚舉類型中都都有什么值,所以能確保你涵蓋了所有的 case: ~~~ func getHaterStatus(weather: WeatherType) -> String? { switch weather { case .Sun: return nil case .Cloud, .Wind: return "dislike" case .Rain: return "hate" } //這段代碼不會成功編譯,應該添加 case .Snow 或是 default case。 } ~~~ 對于 Enum,Swift 還有一個非常強大的特性:可以為組中的值再附加一個值,進一步細分: ~~~ enum WeatherType { case Sun case Cloud case Rain case Wind(speed: Int) case Snow } ~~~ 如此,使用 switch/case 時就有了額外的條件,當條件都滿足時 case 才會匹配: ~~~ func getHaterStatus(weather: WeatherType) -> String? { switch weather { case .Sun: return nil case .Wind(let speed) where speed < 10: //meh return "meh" case .Cloud, .Wind: return "dislike" case .Rain, .Snow: return "hate" } } getHaterStatus(WeatherType.Wind(speed: 5)) ~~~ 代碼段第五行的 let 關鍵字的用途是聲明一個能引用的常量名保存傳入的參數,通過 Where 關鍵字來聲明條件。 Swift 從上至下判斷 switch/case 語句,所以請注意 case 的排序。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看