This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func f() { | |
unowned var unownedValue: NSDate? | |
unownedValue = NSDate() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator *** { | |
precedence 100 | |
associativity none | |
} | |
infix operator +++ { | |
precedence 200 | |
associativity none | |
} | |
func *** (left: Int, right: Int) -> Int { | |
return left * right |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precedencegroup GroupA { | |
associativity: none | |
} | |
precedencegroup GroupB { | |
higherThan: GroupA | |
associativity: none | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # Iterator の実装 | |
// Kotlin | |
// 次の要素があるかどうかは hasNext みる | |
fun next(): T | |
fun hasNext(): Boolean | |
// Swift | |
// 次の要素があるかは next() の返り値の型が Self.Element? なので、これだけで判断可能 | |
func next() -> Self.Element? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var tmp = "tmp"; | |
final finalVar = tmp; | |
// Const variables must be initialized with a constant value. | |
// const constVar = tmp; | |
const _constVar = "const"; | |
const constVar = _constVar; | |
print(finalVar + constVar); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
for (int i = 0; i < 5; i++) { | |
print('hello ${i + 1}'); | |
} | |
for (var i in ["1", false]) { | |
print(convertToBool(i)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v1 + v2 + v3 | |
// evaluation order: v1 v2 v3 | |
v1 + v2 * v3 | |
// evaluation order: v1 v2 v3 | |
v1 + v2 * (v3 + v4) + v5 | |
// evaluation order: v1 v2 v3 v4 v5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var v: Int? | |
if (a?.v = 1) == nil { | |
// if a is nil, do something | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int v = 0; | |
// 意図しているコード | |
if(v == 0) { ... } // `if(1)` と評価 | |
// `==` と `=` を書き間違えたコード | |
if(v = 0) { ... } // `if(0)` と評価 |
NewerOlder