Skip to content

Instantly share code, notes, and snippets.

View oleksii-demedetskyi's full-sized avatar
🎯
Arrow: Language for unidirectional programming

Oleksii Demedetskyi oleksii-demedetskyi

🎯
Arrow: Language for unidirectional programming
View GitHub Profile
//: Playground - noun: a place where people can play
import Cocoa
// Operations
protocol Stringable {
func stringify() -> String
}
protocol Evaluatable {
//: [Previous](@previous)
import Foundation
// One per function
final class Stub {
let name: String
let cmp: (AnyCall, AnyCall) -> Bool
init(name: String, cmp: (AnyCall, AnyCall) -> Bool) {
self.name = name
//: Playground - noun: a place where people can play
import Foundation
func cast<T>(any: Any) -> T {
print(T.self) // Optional<String>
print(any) // nil
let value = any as! T
//Could not cast value of type 'Swift.Optional<Swift.String>' (0x11ad4b028) to 'Swift.String' (0x1118024c8).
print(value)
//: Playground - noun: a place where people can play
import UIKit
protocol SomeServiceProtocol {
func doSomeStuff();
}
class SomeService : SomeServiceProtocol {
func doSomeStuff() {
@oleksii-demedetskyi
oleksii-demedetskyi / ReactiveUI.swift
Created January 4, 2016 13:09
Some useful extension to RAC4
import UIKit
import ReactiveCocoa
// Bind property to any setter
func <~ <T> (left: T->Void , right: AnyProperty<T>) -> Disposable {
return left <~ right.producer
}
// Bind signal producer to any setter
func <~ <T> (left: T->Void , right: SignalProducer<T, NoError>) -> Disposable {
//: Playground - noun: a place where people can play
import UIKit
// Simple struct to be fullfilled from JSON
struct User {
let name: String
let age: Int
}
//: Playground - noun: a place where people can play
protocol Cat {
func meow() -> String
}
protocol Dog {
func bark() -> String
}
@oleksii-demedetskyi
oleksii-demedetskyi / Classes.swift
Created December 25, 2015 10:56
Service locator in swift
class Murzik : Cat {
func meow() -> String {
return "Meeooow"
}
}
class Muhtar : Dog {
func bark() -> String {
return "Woof"
}
@oleksii-demedetskyi
oleksii-demedetskyi / ServiceLocator.swift
Last active December 12, 2020 05:04
Service locator in swift
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
class ServiceLocator {
private var registry : [String: Any] = [:]
func registerService<T>(service: T) {
//: Playground - noun: a place where people can play
class TableView {
init() {}
struct DataSource {
let numberOfRows : () -> Int
}
var delegate : DataSource?