【Swift】基礎知識

3896 ワード

きそぶ
  • タイプ別名(type aliases)
  • Typealias    
      : typealias AudioSample = UInt16 ;  var maxAmplitudeFound = AudioSample.min
    
  • ブールタイプ
  • Swift         ,true   false
    
  • メタグループ(tuples)の複数の値を1つの複合値
  • に組み合わせる
      :let http404Error = (404, “Not Found”); var error: ( code:Int,  msg:String) = (code: 500, msg: "NO Auth")
      :           
    
  • オプションタイプ(optionals)
  • var code:Int ?
    
  • オプションバインド
  •   :var someOptional :Int? ; if let constantName = someOptional { statements }
    

    演算子
  • Null演算子(Nil Coalescing Operator)
  • ?? 
      : a ?? B   ==>    a  !=  nil ?  a!  :  b
    
  • 区間演算子(Range Operators)
  • ...     ..<
      :0 … 5    0 ..< 5
    
  • Swift 3の対++、--のサポート
  • 文字列と文字(Strings and Characters)
  • 文字列可変性
  • var variableString = “Horse”;  variableString += “ and carriage”//     
         ,   let
    
  • 文字列は、値タイプ
  • です.
                 ,        、      ,    /      ,      。      ,              ,               。
    
  • 文字列補間
  • "\() "
    let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"
    
  • 計算文字数
  • "word".characters.count
    

    コレクションタイプ(Collection Type)
    Swiftでvarが出す集合タイプはすべて可変です
  • 配列の要素置換
  • shoppingList[4...6] = ["Bananas", "Apples"]
    
  • 配列の遍歴
  • for (index, value) in shoppingList. enumerated() { print("Item \(String(index + 1)): \(value)") }
    
  • 辞書
  • を巡る
    for (airportCode, airportName) in airports { print("\(airportCode): \(airportName)") }
    
  • キー値ペア
  • を除去する.
    airports["APL"] = nil
    if let removedValue = airports. removeValue(forKey: "DUB") { print("The removed airport's name is \(removedValue).") } else { print("The airports dictionary does not contain a value for DUB.") }
    

    せいぎょりゅう
  • Switch
  •         
        case              。
        ,       
        
        
       (Value Bindings)
    Where,case          where          。
    
  • タグ付き文
  • label name: while condition { statements }
    

    関数#カンスウ#
  • 多重戻り値関数
  • オプション戻り値
  • デフォルトパラメータ値
  • func someFunction(parameterWithoutDefault: Int, parameterWithDefault: Int = 12) {}
    
  • 可変パラメータ
  • func arithmeticMean(_ numbers: Double...) -> Double {}
    
  • 関数タイプ

  • クローズドパッケージ
  • 閉パッケージの3つの形式
  •     
        
         
    
  • 推奨閉パケット構文最適化
  •                
              ,            return    
          
          
    
  • 脱出閉包(@escaping)と非脱出閉包
  • 列挙
  • 関連値
  • enum Barcode { case upc(Int, Int, Int, Int) case qrCode(String) }
    
  • 元の値
  •         
                
    

    コンストラクションプロセス
  • 構築中の定数属性の変更
  • プロパティのデフォルト値
  • を閉パッケージまたは関数で設定します.
    自動参照数
  • 弱引用
  • 主参照なし
  • 閉パケットによるループ強参照
  •             
          
              
    

    アクセス制御
  • open,public,internal,fileprivate,private
  •                 ,               。
                      ,                  。
          ,              ,               。
            ,                ,                 。
             ,     ,                  ,              。
    
  • openとpublicの違いは、publicによって限定されたclassであり、propertyはモジュール内でのみ継承およびリロードされ(ただしモジュール外で呼び出すことができる)、openによって修飾されたclass/propertyはモジュール外でリロードされ得ることである.
  • デフォルトアクセスレベルinternal
  • 上下関係
  • 拡張演算子
  • 優先度と結合性
  • 演算子関数(演算子リロード)
  •                       ,           。
          (operator)