Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RACsignal.toSignalProducer() unavailable #22

Closed
opfeffer opened this issue Apr 3, 2017 · 6 comments
Closed

RACsignal.toSignalProducer() unavailable #22

opfeffer opened this issue Apr 3, 2017 · 6 comments

Comments

@opfeffer
Copy link

opfeffer commented Apr 3, 2017

The README.md reads:

“Hot” RACSignals cannot be directly converted into Signals, because any RACSignal subscription could potentially involve side effects. To obtain a Signal, use RACSignal.toSignalProducer followed by SignalProducer.start, which will make those potential side effects explicit.

I have an instance of RACSignal due to a mixed-language project. Looking through XCode's auto-completion suggestions, I'm not seeing anything like toSignalProducer.

Could I get a code example of how to turn a RACSignal back to Signal?

Thanks!

@andersio
Copy link
Member

andersio commented Apr 3, 2017

You can produce a Signal from a SignalProducer using startWithSignal. Note that the subscription side effect would run after the setUp closure is invoked, but before startWithSignal returns.

signal.toSignalProducer().startWithSignal { signal, interrupter in
    // Do your stuff with `signal`.
}

@opfeffer
Copy link
Author

opfeffer commented Apr 4, 2017

Thanks for getting back to me.

I'm afraid I didn't do a very good job describing my problem - I have an ObjC interface that looks like so:

 @property (nonatomic, strong, readonly) RACSignal<NSDictionary *> *events;

Now, my view/business layer is written in swift mostly and I'm trying to combine events with some other Swift-defined Signals. I was able to achieve the reverse, Swift->ObjC with ReactiveObjCBridge's extensions to SignalProtocol

 public func toRACSignal() -> RACSignal<Self.Value.Wrapped>

but I'm not sure how I can transform a RACSignal to a Signal?

In your response, you said signal.toSignalProducer().startWithSignal { ... }, but events.toSignalProducer() throws compiler warning:

Compiler

What am I missing? Thanks!

@andersio
Copy link
Member

andersio commented Apr 4, 2017

https://github.com/ReactiveCocoa/ReactiveObjCBridge/blob/master/ReactiveObjCBridge/ObjectiveCBridging.swift#L122

It seems it was replaced by bridgedSignalProducer(from:) due to limitations of ObjC generics in Swift.

@opfeffer opfeffer closed this as completed Apr 4, 2017
@NikKovIos
Copy link

NikKovIos commented May 25, 2018

@andersio @opfeffer
Could you please explain how to properly convert RACSignal to SignalProducer?
I've write something like

extension RACSignal {
    func toSignalProducer() -> SignalProducer<ValueType, AnyError> {
        return SignalProducer(self)
    }
}

but the compiler warn at it(

@andersio
Copy link
Member

andersio commented May 30, 2018

@NikKovIos

It should be ValueType? since ValueType is annotated as nullable for API backwards compatibility.

But AFAIK it still won’t compile — there are plenty of restrictions in Swift regarding Objective-C lightweight generics, and they are part of the rationale behind the current interop API besides Swiftification. At least last when we tried, the compiler rejects any extension referring to any generic parameter.

@NikKovIos
Copy link

Yes, so i manually wrap every rac_.. to SignalProducer (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants