【Swift】基礎知識
3896 ワード
きそぶタイプ別名(type aliases) ブールタイプ メタグループ(tuples)の複数の値を1つの複合値 に組み合わせるオプションタイプ(optionals) オプションバインド
演算子 Null演算子(Nil Coalescing Operator) 区間演算子(Range Operators) Swift 3の対++、--のサポート 文字列と文字(Strings and Characters)文字列可変性 文字列は、値タイプ です.文字列補間 計算文字数
コレクションタイプ(Collection Type)
Swiftでvarが出す集合タイプはすべて可変です配列の要素置換 配列の遍歴 辞書 を巡るキー値ペア を除去する.
せいぎょりゅう Switch タグ付き文
関数#カンスウ#多重戻り値関数 オプション戻り値 デフォルトパラメータ値 可変パラメータ 関数タイプ
クローズドパッケージ閉パッケージの3つの形式 推奨閉パケット構文最適化 脱出閉包(@escaping)と非脱出閉包 列挙関連値 元の値
コンストラクションプロセス構築中の定数属性の変更 プロパティのデフォルト値 を閉パッケージまたは関数で設定します.
自動参照数弱引用 主参照なし 閉パケットによるループ強参照
アクセス制御 open,public,internal,fileprivate,private openとpublicの違いは、publicによって限定されたclassであり、propertyはモジュール内でのみ継承およびリロードされ(ただしモジュール外で呼び出すことができる)、openによって修飾されたclass/propertyはモジュール外でリロードされ得ることである. デフォルトアクセスレベルinternal 上下関係 拡張演算子優先度と結合性 演算子関数(演算子リロード)
Typealias
: typealias AudioSample = UInt16 ; var maxAmplitudeFound = AudioSample.min
Swift ,true false
:let http404Error = (404, “Not Found”); var error: ( code:Int, msg:String) = (code: 500, msg: "NO Auth")
:
var code:Int ?
:var someOptional :Int? ; if let constantName = someOptional { statements }
演算子
??
: a ?? B ==> a != nil ? a! : b
... ..<
:0 … 5 0 ..< 5
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.") }
せいぎょりゅう
case 。
,
(Value Bindings)
Where,case where 。
label name: while condition { statements }
関数#カンスウ#
func someFunction(parameterWithoutDefault: Int, parameterWithDefault: Int = 12) {}
func arithmeticMean(_ numbers: Double...) -> Double {}
,
クローズドパッケージ
, return
enum Barcode { case upc(Int, Int, Int, Int) case qrCode(String) }
コンストラクションプロセス
自動参照数
アクセス制御
, 。
, 。
, , 。
, , 。
, , , 。
, 。
(operator)