Last active
August 29, 2015 14:16
-
-
Save yoheiMune/cebf83284008139dd0fc to your computer and use it in GitHub Desktop.
Swift Snipets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 変数の定義(型を推定する) | |
var str = "Hello, playground" | |
var intValue = 1; | |
// 変数の定義(型を明示する) | |
var str2:String = "Good Night"; | |
// 変数の定義 | |
// 初期値も代入せず、型も定義しない場合には、エラーとなる | |
//var type; | |
// 定数 | |
let MAX_VALUE:Int = 999; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 制御文(if) | |
if str == "aaa" { | |
NSLog("GOOD"); | |
} else { | |
NSLog("NOT GOOD"); | |
} | |
// 制御文(switch) | |
switch intValue { | |
case 1: | |
NSLog("value is 1"); | |
case 2, 3, 4: | |
NSLog("Value is 2, 3, or 4"); | |
case 5...7: | |
NSLog("Value is 5 to 7"); | |
default: | |
NSLog("Other Value"); | |
} | |
// 制御文(for-in) | |
for index in 1...10 { | |
NSLog("Value is \(index)"); | |
} | |
// 制御文(for基本形) | |
var array = [1,2,3,4,5]; | |
for var i = 0; i < array.count; i++ { | |
NSLog("array[%d] = %d", i, array[i]); | |
} | |
// 制御文(while) | |
var i = 10; | |
while i > 0 { | |
NSLog("i is %d", i--); | |
} | |
// 制御文(do-while) | |
var j = 10; | |
do { | |
NSLog("j is \(j)"); | |
} while j > 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment