Skip to content

Instantly share code, notes, and snippets.

View ezura's full-sized avatar

Yuka Ezura ezura

View GitHub Profile
import Foundation
func f() {
unowned var unownedValue: NSDate?
unownedValue = NSDate()
}
infix operator *** {
precedence 100
associativity none
}
infix operator +++ {
precedence 200
associativity none
}
func *** (left: Int, right: Int) -> Int {
return left * right
precedencegroup GroupA {
associativity: none
}
precedencegroup GroupB {
higherThan: GroupA
associativity: none
}
@ezura
ezura / CodePiece.swift
Last active November 20, 2018 06:46
Kotlin の Iterator、「次の要素を返す」のと「次の要素があるか」を違うメソッドで管理してるっぽい(´・ω・`)? #CodePiece #speee_lounge #swift #kotlin
// # Iterator の実装
// Kotlin
// 次の要素があるかどうかは hasNext みる
fun next(): T
fun hasNext(): Boolean
// Swift
// 次の要素があるかは next() の返り値の型が Self.Element? なので、これだけで判断可能
func next() -> Self.Element?
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);
}
void main() {
for (int i = 0; i < 5; i++) {
print('hello ${i + 1}');
}
for (var i in ["1", false]) {
print(convertToBool(i));
}
}
@ezura
ezura / CodePiece.swift
Created March 10, 2018 04:24
詳しく調べること: 演算の順番に関わらず、被演算子自身の評価は先頭から順番に行われる #swift #CodePiece
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
enum N {
case never(Never)
}
func f(_ v: N) {
switch v {
case .never(let naver):
print(naver)
}
}
var v: Int?
if (a?.v = 1) == nil {
// if a is nil, do something
}
@ezura
ezura / C言語
Last active January 14, 2018 13:08
どうしてその機能/仕様はSwiftにないのか ref: https://qiita.com/ezura/items/0db0f05add6a8d115f30
int v = 0;
// 意図しているコード
if(v == 0) { ... } // `if(1)` と評価
// `==` と `=` を書き間違えたコード
if(v = 0) { ... } // `if(0)` と評価