Skip to content

Instantly share code, notes, and snippets.

@ezura
Last active January 14, 2018 13:08
Show Gist options
  • Save ezura/638949a10769281e66035879ca367fe3 to your computer and use it in GitHub Desktop.
Save ezura/638949a10769281e66035879ca367fe3 to your computer and use it in GitHub Desktop.
どうしてその機能/仕様はSwiftにないのか ref: https://qiita.com/ezura/items/0db0f05add6a8d115f30
int v = 0;
// 意図しているコード
if(v == 0) { ... } // `if(1)` と評価
// `==` と `=` を書き間違えたコード
if(v = 0) { ... } // `if(0)` と評価
let array = [0, 1]
array[3] // runtime error
let a = 1
if cond {
...
}
let v: Int
if condition {
v = something
} else {
v = other
}
let v: Int = {
if condition {
return something
} else {
return other
}
}()
if cond { ... }
unless !cond { ... }
guard preCondition else {
// can't go next code path
}
i.start; defer { i.end }
let x = cond ? 4 : 8
let x = if cond then 4 else 8
let x = if cond then
some_long_expression
else
some_other_long_expression
let a = 1
if cond {
...
}
i.start; defer { i.end }
let x = cond ? 4 : 8
let x = if cond then 4 else 8
let x = if cond then
some_long_expression
else
some_other_long_expression
let v: Int = if condition {
return something
} else {
return other
}
var v = false
// 意図しているコード
if v == false { ... } // `if true` と評価
// `==` と `=` を書き間違えたコード
if v = false { ... } // ❗️文法エラー
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment