Skip to content

Instantly share code, notes, and snippets.

@SatoTakeshiX
Last active February 3, 2016 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SatoTakeshiX/0a412239fe528e3c1a8b to your computer and use it in GitHub Desktop.
Save SatoTakeshiX/0a412239fe528e3c1a8b to your computer and use it in GitHub Desktop.
Swifのクラスと構造体サンプル
//: Playground - noun: a place where people can play
import UIKit
/*
関数の定義
*/
//引数をとらない関数
func someFunc(){
print("引数も戻り値もない関数")
}
//引数を一つもって戻り値がある関数
func sampleFunc(string : String) -> String{
return string
}
someFunc()
print(sampleFunc("引数と戻り値がある"))
UIView.animateWithDuration(10, animations: {})
/*
外部引数名と内部引数名
*/
func SumNumber (firstNumber x: Int, secondNumber y: Int) -> Int{
return x + y
}
SumNumber(firstNumber: 1, secondNumber: 2)
//SumNumber(secondNumber: 2, firstNumber: 3)
func SumSumNumber (Number x: Int, Number y: Int) -> Int{
return x + y
}
SumSumNumber(Number: 1, Number: 1)
/*
二番目の引数名を省略
_アンダーバーを使う
*/
func CalculationArea(width : Int , _ height : Int) -> Int{
return width * height
}
CalculationArea(12, 13)
/*
内部引数名を_にすることで処理しない
*/
func CalculationAreaWithBool(width : Int , _ height : Int, _ _ :Bool) -> Int{
return width * height
}
CalculationAreaWithBool(10, 22, true)
//戻り値を無視する
let _ = CalculationAreaWithBool(10, 10, false)
//指定回数実行する
for _ in 1...10{
print("10回だけ実行!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment