Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active September 12, 2017 10:23
Show Gist options
  • Save KentarouKanno/01db0fde78a60156433e to your computer and use it in GitHub Desktop.
Save KentarouKanno/01db0fde78a60156433e to your computer and use it in GitHub Desktop.
Swift

#Swift

★ 変数の中身を入れ替える

var a = "a"
var b = "b"

swap(&a, &b)

a
//=> "b"
b
//=> "a"

★ タプルで入れ替える

var a = "a"
var b = "b"

(b, a) = (a, b)

★ 絶対値を返す

var a = -10

var b = abs(a)
//=> b = 10

★ 最大値を返す

var m = max(45, 28, 5, 61, 10, 2, 56, 33, 18, 3)
//=> 61

★ 最小値を返す

var m = min(45, 28, 5, 61, 10, 2, 56, 33, 18, 3)
//=> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment