Skip to content

Instantly share code, notes, and snippets.

View ahernandezlopez's full-sized avatar

Albert Hernández ahernandezlopez

View GitHub Profile
@ahernandezlopez
ahernandezlopez / DomainEvents-3.swift
Last active October 25, 2017 06:58
Example of implementation of Domain Events in Swift. The snippet illustrates Domain Events in a Service with RxSwift
import RxSwift
import UIKit
class ListingListViewController: UIViewController {
let contentView: ListingListView
let service: ListingService
let disposeBag: DisposeBag
init(service: ListingService) {
self.contentView = ListingListView()
@ahernandezlopez
ahernandezlopez / DomainEvents-2.swift
Last active October 25, 2017 06:31
Example of implementation of Domain Events in Swift. The snippet illustrates Domain Events in a Service with RxSwift
import RxSwift
class LocalListingService: ListingService {
var events: Observable<ListingServiceEvent> {
return eventsPublishSubject.asObservable()
}
private let eventsPublishSubject: PublishSubject<ListingServiceEvent>
// ...
@ahernandezlopez
ahernandezlopez / DomainEvents.swift
Last active October 23, 2017 11:50
Example of implementation of Domain Events in Swift. The snippet illustrates Domain Events in a Service with RxSwift
protocol ListingService: class {
var events: Observable<ListingServiceEvent> { get }
func filteredEvents(listing: Listing) -> Observable<ListingServiceEvent>
func create(params: ListingServiceCreateParams,
completion: ((Result<Listing, ListingServiceCreateError>) -> ())?)
func update(listing: Listing,
params: ListingServiceUpdateParams,
completion: ((Result<Listing, ListingServiceUpdateError>) -> ())?)
func delete(listing: Listing,
@ahernandezlopez
ahernandezlopez / CrashlyticsLogger.swift
Last active November 7, 2017 07:52 — forked from akramhussein/CrashlyticsLogger.swift
CocoaLumberjack Custom Crashlytics Logger in Swift
import Foundation
import CocoaLumberjack
import Crashlytics
class CrashlyticsLogger : DDAbstractLogger
{
static let sharedInstance = CrashlyticsLogger()
private var _logFormatter : DDLogFormatter?
override var logFormatter: DDLogFormatter? {
@ahernandezlopez
ahernandezlopez / SequenceType+Upcast.swift
Last active March 21, 2018 07:20
Useful for SequenceType upcasting, i.e. for upcasting "array of protocol implementers" to array of protocol
extension SequenceType {
func upcast<T, U where Self.Generator.Element == T>() -> [U] {
return flatMap {$0 as? U}
}
}