Rxswift: Ambiguous use of delegate

Created on 12 Dec 2017  路  2Comments  路  Source: ReactiveX/RxSwift

Short description of the issue:

I have a swift file which is written by others and run smoothly in project A. However I put it into project B, it failed and show me error of
UIImagePicker+Rx.swift:29:16: Ambiguous use of 'delegate'
UIImagePicker+Rx.swift:40:16: Ambiguous use of 'delegate'

Code:

import Foundation
import RxSwift
import RxCocoa
import UIKit

extension Reactive where Base: UIImagePickerController {

    /**
     Reactive wrapper for `delegate`.

     For more information take a look at `DelegateProxyType` protocol documentation.
     */
    public var delegate: DelegateProxy {
        return RxImagePickerDelegateProxy.proxyForObject(base)
    }

    /**
     Reactive wrapper for `delegate` message.
     */
    public var didFinishPickingMediaWithInfo: Observable<[String : AnyObject]> {
        return delegate
            .methodInvoked(#selector(UIImagePickerControllerDelegate.imagePickerController(_:didFinishPickingMediaWithInfo:)))
            .map({ (a) in
                return try castOrThrow(Dictionary<String, AnyObject>.self, a[1])
            })
    }

    /**
     Reactive wrapper for `delegate` message.
     */
    public var didCancel: Observable<()> {
        return delegate
            .methodInvoked(#selector(UIImagePickerControllerDelegate.imagePickerControllerDidCancel(_:)))
            .map {_ in () }
    }

}

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
}

RxSwift 3.0

Platform/Environment

  • [x] at least iOS 9.0

Xcode version:

  8.3.3

Installation method:

  • [x] CocoaPods

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • [x] yes (which ones)
    8.3.3 and 9.0

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • [x] I have a small code base

Most helpful comment

can you please share the podfile (or list of dependecies) used on Project B? Seems to me you already have another implementation of Reactive<UIImagePickerController>.delegate. I guess removing public var delegate from this file will compile your code.

All 2 comments

can you please share the podfile (or list of dependecies) used on Project B? Seems to me you already have another implementation of Reactive<UIImagePickerController>.delegate. I guess removing public var delegate from this file will compile your code.

Thank you so much, it works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RobinFalko picture RobinFalko  路  3Comments

delebedev picture delebedev  路  3Comments

jeremiegirault picture jeremiegirault  路  3Comments

gaudecker picture gaudecker  路  3Comments

acecilia picture acecilia  路  3Comments