Help us understand the problem. What is going on with this article?

Swiftのreturnが要らなくなってる?

More than 1 year has passed since last update.

なんかSwiftの使用がいつの間に変わってたので情報共有
funcgetでも1行であればreturnが要らなくなってる。

以前

// 昔からこれはOKだった
let hello:() -> String = {
    "Hello"
}


func hello() -> String {
    return "Hello" // 関数ではreturn必須だった
}

var value:Int {
    return 10 + 10 // getterでも必須だった
}

var _hiddenValue = 0
var value:Int { // getterでも必須だった
    get {return _hiddenValue}
    set {_hiddenValue = newValue}
}

今回

いつの間にか関数などのブロックの動きがクロージャと同じになってました。

let hello:() -> String = {
    "Hello"
}


func hello() -> String {
   "Hello"
}

var value:Int {
   10 + 10
}

var _hiddenValue = 0
var value:Int {
    get {_hiddenValue}
    set {_hiddenValue = newValue}
}

特にgetterなんかはいつもreturnを書く必要性に疑問を感じていたので嬉しいです。

いつからこうなったんだろう...?

ObuchiYuki
未踏2020/アプリ甲子園優勝/U22プロコン経済産業省商務局長賞/セキュキャンアワード /seccamp19/香港→開成→mast19
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした