Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
3 contributors

Users who have contributed to this file

@kzaher @MortyMerr @diogot
49 lines (38 sloc) 1.34 KB
//
// UIImagePickerController+Rx.swift
// RxExample
//
// Created by Segii Shulga on 1/4/16.
// Copyright © 2016 Krunoslav Zaher. All rights reserved.
//
#if os(iOS)
import RxSwift
import RxCocoa
import UIKit
extension Reactive where Base: UIImagePickerController {
/**
Reactive wrapper for `delegate` message.
*/
public var didFinishPickingMediaWithInfo: Observable<[UIImagePickerController.InfoKey : AnyObject]> {
return delegate
.methodInvoked(#selector(UIImagePickerControllerDelegate.imagePickerController(_:didFinishPickingMediaWithInfo:)))
.map({ (a) in
return try castOrThrow(Dictionary<UIImagePickerController.InfoKey, AnyObject>.self, a[1])
})
}
/**
Reactive wrapper for `delegate` message.
*/
public var didCancel: Observable<()> {
return delegate
.methodInvoked(#selector(UIImagePickerControllerDelegate.imagePickerControllerDidCancel(_:)))
.map {_ in () }
}
}
#endif
private func castOrThrow<T>(_ resultType: T.Type, _ object: Any) throws -> T {
guard let returnValue = object as? T else {
throw RxCocoaError.castingError(object: object, targetType: resultType)
}
return returnValue
}
You can’t perform that action at this time.