Skip to content

Instantly share code, notes, and snippets.

View yoching's full-sized avatar
👋

Yoshikuni Kato yoching

👋
View GitHub Profile
protocol XibInstantiatable {
func instantiate()
}
extension XibInstantiatable where Self: UIView {
func instantiate() {
let nib = UINib(nibName: String(self.dynamicType), bundle: nil)
guard let view = nib.instantiateWithOwner(self, options: nil).first as? UIView else {
return
}
@yoching
yoching / RACSignalExperiments.swift
Last active August 3, 2016 14:24
Questions about RAC signal deallocation.
// case 1: using pipe
class A {
let signal: Signal<Void, NoError>
let observer: Signal<Void, NoError>.Observer
init() {
(signal, observer) = Signal<Void, NoError>.pipe()
}
@yoching
yoching / ReactiveSwiftBasicComponentSamples.swift
Last active July 31, 2018 07:21
ReactiveSwift basic components samples
struct MyError: Error {
}
//// Signal
print("------ Signal basic ------")
let (signal, innerObserver) = Signal<Int, MyError>.pipe()
signal.observeResult { result in
switch result {
@yoching
yoching / experiment.swift
Last active May 30, 2017 03:32
swift tuple parameter experiments
func someFunc(a: Int, b: Int) -> String {
return "a = \(a), b = \(b)"
}
let parameters = (a: 0, b: 0)
// someFunc(parameters) // not allowed in swift 3
let numbers: [Int] = [1, 2, 3]
numbers
.map { number -> (a: Int, b: Int) in
@yoching
yoching / FuctionalViewStyleExperiments1.swift
Last active September 7, 2017 07:34
FuctionalViewStyleExperiments1
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
import PlaygroundSupport
let viewController = UIViewController()
viewController.view.backgroundColor = .white
@yoching
yoching / FunctionalViewStyleExperiments2.swift
Created September 7, 2017 07:35
FunctionalViewStyleExperiments2
//: Playground - noun: a place where people can play
import UIKit
import UIKit
import XCPlayground
import PlaygroundSupport
let viewController = UIViewController()
@yoching
yoching / StubConfigurator.swift
Created September 19, 2017 03:16
OHHTTPStubs wrapper
public protocol ApiRequestSetting {
static var hostname: String { get }
static var basePath: String { get }
}
final class StubConfigurator {
private let setting: ApiRequestSetting.Type
init(setting: ApiRequestSetting.Type) {
@yoching
yoching / iOSAppDevelopmentPreparations.md
Last active October 1, 2017 06:22
新規アプリ開発時の決めることリスト

前提

プロジェクトの性質

(規模、期間、運用の有無、注力する点、制約、一般的なプロジェクトとの違いなど)

プロダクトの性質

(使う技術、Framework、対応OS、対応端末など)

開発者のモチベーション

(やりたいこと、最近の流行、前のプロジェクトの反省点など)

class CustomNavigationController: UINavigationController {
var token: NSKeyValueObservation?
override func viewDidLoad() {
super.viewDidLoad()
token = self.observe(\.viewControllers) { observed, change in
print(observed)
print(change)
}
@yoching
yoching / SingleOrMultiple.swift
Last active April 12, 2018 06:07
Data container which express single or multiple ojects
enum SingleOrMultiple<Value> {
case single(Value)
case multiple([Value])
func map<T>(_ transform: (Value) throws -> T) rethrows -> SingleOrMultiple<T> {
switch self {
case let .single(value): return .single(try transform(value))
case let .multiple(values): return .multiple(try values.map(transform))
}
}