You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

//
// UIImagePickerController+Rx.swift
// RxExample
//
// Created by Segii Shulga on 1/4/16.
// Copyright © 2016 Krunoslav Zaher. All rights reserved.
//
import RxSwift
import RxCocoa
import UIKit
//UIImagePickerControllerRx
extension Reactive where Base: UIImagePickerController {
//
public var pickerDelegate: DelegateProxy<UIImagePickerController,
UIImagePickerControllerDelegate & UINavigationControllerDelegate > {
return RxImagePickerDelegateProxy.proxy(for: base)
}
//
public var didFinishPickingMediaWithInfo: Observable<[String : AnyObject]> {
return pickerDelegate
.methodInvoked(#selector(UIImagePickerControllerDelegate
.imagePickerController(_:didFinishPickingMediaWithInfo:)))
.map({ (a) in
return try castOrThrow(Dictionary<String, AnyObject>.self, a[1])
})
}
//
public var didCancel: Observable<()> {
return pickerDelegate
.methodInvoked(#selector(UIImagePickerControllerDelegate
.imagePickerControllerDidCancel(_:)))
.map {_ in () }
}
}
//Error
fileprivate 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
}