This file contains hidden or 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 UIKit | |
import Swinject | |
protocol InjectionSegueType { | |
typealias Source: UIViewController | |
typealias Destination: UIViewController | |
var sourceController: Source { get } |
This file contains hidden or 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
struct Container<T> { | |
let value: T | |
} | |
let a = Container(value: "a") | |
a.value // "a" | |
let b = Container(value: ("b", 2)) | |
b.value // (.0 "b", .1 2) |
This file contains hidden or 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
enum Animal { | |
case Cat | |
case Dog(kind: String) | |
case Human | |
} | |
func hoge(animal: Animal, isTamed: Bool, age: Int) { | |
switch (animal, isTamed) { | |
case (.Cat, true): | |
print("tamed cat") |
This file contains hidden or 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
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
switch (tableView.dequeueReusableCellWithIdentifier("cardCell", forIndexPath: indexPath), hand[indexPath.row]) { | |
case (let cell as? CardCell, let data as? Card): | |
cell.fillWith(data) | |
case (let cell as? HogeCell, let data as? Hoge): | |
cell.fillWith(data) | |
case (let cell as? FugaCell, let data as? Fuga): | |
cell.fillWith(data) | |
default: |
This file contains hidden or 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
let a: Int = [10,10,10] | |
.enumerate() | |
.reduce(0) { (sum: Int, item: (index: Int, value: Int)) in | |
sum + item.value + (item.index == 0 ? 0 : 1) | |
} |
This file contains hidden or 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
// 最初のコード | |
protocol FoodType {} | |
struct Spirit: FoodType {} | |
struct Meet: FoodType {} | |
protocol MonsterType { | |
typealias Food: FoodType | |
} |
This file contains hidden or 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
struct Hoge { | |
lazy var fuga: String = "fuga" | |
} | |
let hoge = Hoge() | |
let str = hoge.fuga // Cannot use mutating getter on immutable value: 'hoge' is a 'let' constant |
This file contains hidden or 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
func uekizan<S: SequenceType>(sources: S, insert margin: S.Generator.Element) -> AnyGenerator<S.Generator.Element> { | |
var gen = sources.generate() | |
var isMargin = false | |
var preserved: S.Generator.Element? = gen.next() | |
return anyGenerator { | |
defer { | |
isMargin = !isMargin | |
} | |
switch (isMargin, preserved) { |
This file contains hidden or 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
func uekizanGenerator<S: SequenceType>(sources: S, insert margin: S.Generator.Element) -> AnyGenerator<S.Generator.Element> { | |
var gen = sources.generate() | |
var isMargin = false | |
var preserved: S.Generator.Element? = gen.next() | |
func getMargin() -> S.Generator.Element? { | |
guard preserved != nil else { return nil } | |
return margin | |
} |
This file contains hidden or 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
struct UekizanGenerator<S: SequenceType, E where S.Generator.Element == E> : GeneratorType { | |
typealias Element = E | |
private let margin: E | |
private var elementGenerator: S.Generator | |
private var preserved: E? | |
private var isMargin = false | |
init(_ sources: S, margin: E) { | |
self.margin = margin |