Skip to content

Instantly share code, notes, and snippets.

@josafafilho
Created July 19, 2015 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josafafilho/a2d5ff17c2c4228d5115 to your computer and use it in GitHub Desktop.
Save josafafilho/a2d5ff17c2c4228d5115 to your computer and use it in GitHub Desktop.
ReactiveCocoa Swift Extension
// ReactiveCocoaExtension.swift
//
// Simple ReactiveCocoa Swift extensions using generics
// Created by josafafilho<josafafilho15@gmail.com> on 7/19/15.
import Foundation
import ReactiveCocoa
extension RACSignal {
func subscribeNextAs<T>(nextClosure:(T) -> ()) -> () {
self.subscribeNext {
(next: AnyObject!) -> () in
let nextAsT = next as! T
nextClosure(nextAsT)
}
}
func filterAs<T>(filterClosure:(T) -> Bool) -> RACSignal {
return self.filter { filter -> Bool in
let filterAsT = filter as! T
return filterClosure(filterAsT)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment