2015-03-24から1日間の記事一覧

Swift入門メモ -列挙型-

15 列挙型 #15 列挙型を使ってみよう | Swift入門dotinstall.com あるデータが取り得る値を一覧にしたデータ型 1文字目は必ず大文字 // 1文字目は必ず大文字 enum Result { case Success case Error } var r: Result r = Result.Success // rがResult型とい…

Swift入門メモ -関数-

13,14 関数を使う #13 関数を使ってみよう (1) | Swift入門dotinstall.com #14 関数を使ってみよう (2) | Swift入門dotinstall.com 関数とは 複数の処理をまとめることができる 基本形 func sayHello() { println("Hello") } sayHello() // 関数呼び出し「He…

Swift入門メモ -Optional-

12 Optional #12 Optionalを使ってみよう | Swift入門dotinstall.com Optionalではない型はnilになり得ない決まり あるデータがnilかどうか曖昧なままだと重大なエラーが起きやすいという傾向があるため(※よくわかってない) var s: String s = nil // エラ…

Swift入門メモ -while・do...while・for-

10 while,do…while #10 while、do ... whileを使ってみよう | Swift入門dotinstall.com ある条件を満たしている間処理を繰り返す whileは条件判定が前 do…whileは条件判定が後なので、必ず1回実行される // while var n = 0 while n < 10 { println(n) n++ } …

Swift入門メモ -if・switch-

08 ifで条件分岐 #08 ifで条件分岐をしてみよう | Swift入門dotinstall.com 何らかの条件に応じて処理を振り分けたいとき 比較演算子を使う > >= < <= == != let score = 62 var result = "" if score > 80 { result = "Great" } else if score > 60 { resul…

Swift入門メモ -タプル・配列・辞書-

05 タプルを使ってみよう #05 タプルを使ってみよう | Swift入門dotinstall.com タプル->複数の値をまとめて渡すときによく使われる // タプル let error = (404, "not found") error.0 // 404 error.1 // not found // 名前を付ける let error2 = (code: 40…