swift - 'return' cannot transfer control out of a defer statement - TagMerge
1'return' cannot transfer control out of a defer statement'return' cannot transfer control out of a defer statement

'return' cannot transfer control out of a defer statement

Asked 11 months ago
0
1 answers

  1. Returning more than one value is not allowed, regardless of whether you try to do that in a defer statement or not.

  2. Whatever you do to mutate a return value in a defer statement, that's not accessible via a return. It happens afterward.

func someone() -> String {
  var `return` = "Hello"

  defer {
    `return` += "World"
  }

  return `return`
}

someone() // Hello

Source: link

Recent Questions on swift

    Programming Languages