Skip to content

Instantly share code, notes, and snippets.

View rizumita's full-sized avatar
🏠
Working from home

Ryoichi Izumita rizumita

🏠
Working from home
View GitHub Profile
@rizumita
rizumita / BundleSegue.swift
Last active March 9, 2016 15:32
Using UIStoryboardSegue for purposes of injecting dependencies and passing data
class BundleSegue: ConfigurationSegue {
typealias Source = BundlesViewController
typealias Destination = BundleViewController
typealias First = BundlesViewController
typealias Second = BundleViewController
override func inject() {
destinationController.viewModel = resolver.resolve(BundleViewModelType.self)
import UIKit
protocol GiverType {
var message: String { get }
}
protocol ReceiverType: class {
var message: String? { get set }
}
import UIKit
protocol GiverType {
var message: String { get }
}
protocol ReceiverType: class {
var message: String? { get set }
}
@rizumita
rizumita / Assembly
Last active February 22, 2016 14:00
SegueOperatorはSegueに取り付けられる交換手クラスです。BundlesWireframeはVIPERアーキテクチャの遷移を司るクラスです。
/*
* SwinjectでSegueにInjectするSegueOperatorTypeを指定する。
* nameにSegueのIdentifierを指定する。
*/
container.register(SegueOperatorType.self, name: "BundlesSegue") { _ in
return SegueOperator {
_, _ in
print("test")
}
}
viewController?.performSegueWithIdentifier(R.segue.bundlesViewController.bundleSegue.identifier,
sender: TransitionOperator {
(e: UIStoryboardSegue, s: BundlesViewController, d: BundleViewController) in
d.id = id
})
func showNextPage(id: Int) {
performSegueWithIdentifier("MySegue", sender: TransitionOperator {
(e: UIStoryboardSegue, _, d: DestinationViewController) in
d.id = id
})
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
switch sender {
case let transitionOperator as TransitionOperatorType:
@rizumita
rizumita / CodePiece.swift
Created February 25, 2016 07:25
このコードはviewControllersは2つVCが入ってるArray?。objにはそのArrayが入ってくる。forにOptionalが渡せているという事になる。 #swift #CodePiece
var viewController: SampleViewController? {
let viewControllers = handler?.allViewControllers
for obj in viewControllers {
print(obj)
}
return nil
}
@rizumita
rizumita / gist:a9e510b4cf28d8207a00
Last active March 9, 2016 06:46
protocol with init in Swift
private protocol P1 {
var p1: String { get }
var p1_ : String { get set }
init()
init(p1: String)
}
extension P1 {
init(p1: String) {
self.init()
@rizumita
rizumita / file0.swift
Created March 19, 2016 13:02
ズンドコキヨシをSwiftのAnyGeneratorとlazyで ref: http://qiita.com/rizumita/items/07640c4adf208d52b91d
enum Zundoko: String {
case Zun = "ズン"
case Doko = "ドコ"
}
var zundoko = Array<Zundoko>()
let gen = anyGenerator { return arc4random_uniform(2) == 0 ? Zundoko.Zun : Zundoko.Doko }
.lazy
.map { (zd) -> [Zundoko] in
zundoko.append(zd)
@rizumita
rizumita / pe_9.swift
Last active March 31, 2016 01:52
Project Euler #9 in Swift
class TripleGenerator: GeneratorType {
static let max: Int = 1000
typealias Element = Triple
var triple: Triple? = Triple(a: 3, b: 4, c: 5)
func nextTriple(a a: Int, b: Int) -> Triple? {
var nextA = a
var nextB = b