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()
}
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
}
var global: Any? = nil
class A {
deinit {
global = self
}
}
do {
_ = A()
/*
event | without didSet | have didSet
start 0 0
0 0
set 1 1
1 0
1 0
1 0
end 1 1
--- 1
@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)` と評価

Typed error can be useful in certain cases, especially when accompanied with NoError type.

For example, in reactive programming, https://github.com/ReactiveCocoa/ReactiveSwift (typed error) allows us to create UI bindings only if Error is NoError, i.e.:

static func <~ <Source: BindingSource> (provider: Self, source: Source) -> Disposable? 
    where Source.Value == Value, Source.Error == NoError { ... }
    
// example
let alphaSignal: Signal = ...