Reactive cocoa attemptmap return type

261 Views Asked by At

I want to create extension on SignalProducerType as below.

extension SignalProducerType{
    func mapR() -> SignalProducer<[String:AnyObject], XError> {
            return attemptMap { (value: [String:AnyObject]) -> Result<[String:AnyObject], XError> in
                return Result(value: ["1":1])
            }
        }
}

XError is defined as ErrorType

public enum XError: ErrorType{
    case Invalid
    case Unsuccessful
}

But this won't compile and error is.

'attemptMap' produces 'SignalProducer', not the expected contextual result type 'Result<[String : AnyObject], XError>' (aka 'Result, XError>')

1

There are 1 best solutions below

0
Cosyn On

You are extending SignalProducerType who has generic associated types Value and Error, which means self is a generic type e.g. SignalProducer<Value, Error>. So you can't call attempMap with concrete value type [String:AnyObject] and concrete error type XError.

Replace the first line extension SignalProducerType with

extension SignalProducerType where Value == [String:AnyObject], Error == XError