Skip to content

Instantly share code, notes, and snippets.

View ezura's full-sized avatar

Yuka Ezura ezura

View GitHub Profile
@ezura
ezura / CodePiece.swift
Created August 3, 2017 14:07
こういうの欲しい #swift #CodePiece
protocol P<E> { ... }
let p: P<String>
@ezura
ezura / CodePiece.swift
Created July 28, 2017 16:19
これなら、純粋な、実装だけの存在となれるかなぁ(。 ・ω・)) #swift #CodePiece
protocol P { var v: String { get } }
func f() -> P {
struct InnerType: P {
let v = "inner"
}
return InnerType()
}
f().v // inner
@ezura
ezura / CodePiece.swift
Created July 15, 2017 07:32
`unowned(unsafe)`、`unowned(safe)` があることに気づいた(゚ω゚) 予約語リストに加えた! #swift #CodePiece
// unowned = unowned(safe)
unowned(safe) var safe: AnyObject
{ [unowned(safe) a] in /* ... */ }
// like `__unsafe_unretained`
unowned(unsafe) var unsafe: AnyObject
{ [unowned(unsafe) a] in /* ... */ }
// > Updated the discussion of protocol extensions in Extension Declaration now that final isn’t allowed in them.
// https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/RevisionHistory.html
// https://web.archive.org/web/20170221062722/https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html
// https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/doc/uid/TP40014097-CH34-ID378
class A {}
extension A {
final func f() {}
}
A().f()
@ezura
ezura / CodePiece.swift
Created July 12, 2017 13:53
将来的にこういうのができるようになるっぽい?(任意の列挙子を全網羅の対象から外す) #swift #CodePiece
enum Enum {
case a
case b
@_downgrade_exhaustivity_check
case c
}
// Compile: OK (warning)
switch Enum.a {
case .a: break
@ezura
ezura / enum.swift
Last active July 23, 2017 07:49
enum E<T: ExpressibleByIntegerLiteral>
enum E<T: ExpressibleByIntegerLiteral>: T where T: Equatable {
case a = 1
}
struct MyType: ExpressibleByIntegerLiteral, Equatable {
let v: String
init(integerLiteral value: IntegerLiteralType) { v = String(value) }
static func ==(lhs: MyType, rhs: MyType) -> Bool { return true }
}
@ezura
ezura / CodePiece.swift
Created July 10, 2017 14:04
こう #swift #CodePiece
enum E<T: ExpressibleByIntegerLiteral>: T where T: Equatable {
case a = 1
}
// ...
let ei: E<Int> = .a
let et: E<MyType> = .a
let i: E<Int> = E<Int>.a.rawValue
@ezura
ezura / CodePiece.swift
Created July 10, 2017 13:50
寝る前にこの感動コードを投下しよう(゚ω゚) #swift #CodePiece
enum E<T: ExpressibleByIntegerLiteral>: T where T: Equatable {
case a = 1
}
public static final void f() {
Integer v = Integer.valueOf(300);
Integer v2 = Integer.valueOf(300);
boolean var10000;
if(v == v2) {
var10000 = true;
} else {
var10000 = false;
}
class S {
fun f(v: Int): String = "f"
}
fun main() {
var sf: (S, Int) -> String = S::f
var _sf: S.(Int) -> String = sf
val sf1: String = sf(S(), 1)
val sf2: String = _sf(S(), 1)
}