Getting "use of undeclared type 'NoError'" with ReactiveCocoa
Asked Answered
S

3

13

I am trying to learn ReactiveCocoa and have a hard time getting started. I keep hitting minor bumps as API and tutorials seems to be outdated quickly. Maybe I have the wrong impression.

Just trying to follow this I do not seem to have NoError.

enter image description here

It should be imported correctly, since I have access to Signal, rac_textSignal etc. but I don't know why NoError is not available.

Their documentation mentions NoError as well but that leads to a 404.

This transition to RAC4 mentions NoError as well. Why is NoError undeclared? I am using ReactiveCocoa 4.0.1.

Edit: I just added public enum NoError : ErrorType {} to the top of the file and it works now. I am not sure if this is a proper solution to the problem though. It is not mentioned in guides and tutorials that I should extend ErrorType myself.

Spicebush answered 4/2, 2016 at 15:53 Comment(0)
A
24

The reactive cocoa native NoError was removed in 4.0.1 in favour of antitypicals implementation in Result (adds NoError to Result, see this). See e.g. issue #2704

We can see this explicitly used in the source files, e.g.

Hence, you probably need to include (antitypicals) Result whenever you intend to use NoError. One suggested fix in the issue thread is

public typealias NoError = Result.NoError
Andrey answered 4/2, 2016 at 16:31 Comment(3)
Thanks, people seem to complain about breaking changes, I would not have figured this out. import enum Result.NoError and then typealias the error works for me.Spicebush
@Spicebush Happy to help. Since that works fine for you, your probably wont need it, but I'd keep an eye out on that open issue just in case.Andrey
That's true, this was technically a breaking change that we did not foresee.Masoretic
I
4

If you are seeing this now with ReactiveSwift 6.0, they removed the dependency on Result, which removes NoError.

Per their release notes here, the solution is to now use Never.

  • If you have used Result only as dependency of ReactiveSwift, remove all instances of import Result, import enum Result.NoError or import struct Result.AnyError and remove the Result Framework from your project.
  • Replace all cases where NoError was used in a Signal or SignalProducer with Never

The following example code shows how this should look now:

import ReactiveSwift

func example() -> SignalProducer<Void, Never> {
    return SignalProducer(value: ())
}
Illogicality answered 3/5, 2019 at 3:22 Comment(0)
E
2

If you add "import Results" to the top of the page above your class, NoError will no longer be an undeclared type!

Elutriate answered 16/12, 2016 at 21:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.