0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

クロージャの省略型

Last updated at Posted at 2024-02-08

雛形

var sum: (Int, Int) -> Int  
sum = { (x: Int, y: Int) -> Int in  
  return x + y
}
let a = sum(1, 2)// 3

return省略

var sum: (Int, Int) -> Int  
sum = { (x: Int, y: Int) -> Int in  
  x + y
}
let a = sum(1, 2)// 3

型の省略

var sum: (Int, Int) -> Int  
sum = { (x, y) in  
  x + y
}
let a = sum(1, 2)// 3

括弧の省略

var sum: (Int, Int) -> Int  
sum = { x, y in  
  x + y
}
let a = sum(1, 2)// 3

簡略引数名の利用

var sum: (Int, Int) -> Int  
sum = { $0 + $1 }
let a = sum(1, 2)// 3
0
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?