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

switch fails assert if the receiver sends nil #82

Closed
Coneko opened this issue Oct 12, 2012 · 5 comments
Closed

switch fails assert if the receiver sends nil #82

Coneko opened this issue Oct 12, 2012 · 5 comments
Labels

Comments

@Coneko
Copy link
Member

Coneko commented Oct 12, 2012

If a subscribable sends nil, then switch fails it's assert:

NSAssert2([x conformsToProtocol:@protocol(RACSubscribable)], @"-switch requires that the source subscribable (%@) send subscribables. Instead we got: %@", self, x);

From a cursory glance at the code there doesn't seem to be any practical reason why nil wouldn't be a valid value.
Is requiring a non-nil subscribable a design choice or just something that never came up?

@jspahrsummers
Copy link
Member

@joshaber can speak to whether this was an intentional design choice, but I'd argue that it's the correct one. A subscribable of subscribables shouldn't send nil, because references to subscribables just generally shouldn't be nil. If you need to represent a nil or empty value, create a subscribable that returns it immediately.

@Coneko
Copy link
Member Author

Coneko commented Oct 12, 2012

I can see the logic behind that, and I would agree with it if it were an isolated matter, but it makes using subjects as properties a bit cumbersome.

Consider

[RACAble(self.object.subjectProperty) switch]

Even if whatever object is makes sure that subjectProperty is never set to nil, you'd still have to make sure the object property on self is never set to nil (and since object is not a subscribable itself, a nil value could make perfect sense), or use

[[[RACAble(self.object) where:^BOOL(id x) {
    return x != nil;
}] select: ^id(id x) {
    return [x subjectProperty];
}] switch]

instead.

The problem is compounded if you use subscribables that send objects that have subscribable properties.
A simple chain of select, switch and RACAble would have to be interspersed with where everywhere.
Even if it might not be strictly correct, I'd like to be able to switch nil subscribables because of this.

@jspahrsummers
Copy link
Member

👍 Those are good points. I think -switch should be updated.

@joshaber joshaber mentioned this issue Oct 12, 2012
@joshaber
Copy link
Member

Makes sense to me 👍 PR opened.

@Coneko
Copy link
Member Author

Coneko commented Oct 13, 2012

Looks good, thanks for the fix and fast feedback.

@Coneko Coneko closed this as completed Oct 13, 2012
andersio pushed a commit that referenced this issue Sep 22, 2016
Update RAC to 4.0 final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants