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
Stop fatal error on non convertible value in 'RKKeyValueSignal' #290
Comments
You are right, we should improve that. Let me tackle the problem alongside the update I'm doing for #288. |
Thanks! You know I'm always willing to make PRs but I'm not sure exactly how you want to tackle this one, so if you are already handling it that's great. As always, thanks for all your hard work. |
@srdanrasic I'd really love to see this implemented soon. I know you're probably super busy, but if you have the time to even discuss what for you are thinking these errors would take, I'd be happy to help with a PR for this and #288. |
Hey @AnthonyMDev, sorry for the slow progress during the past week. I moved to another country so I had very little time. Fortunately things are settling down now and I got some time during the weekend to work on this. Please check out beta9. KVO key path can now be represented using a In addition, deallocation handling is now improved and observation will be disposed just before the target object is deallocated. Observation does not need to hold a strong reference any more. I still did not battle test this, but from extensive play in playgrounds there seems to be no issues. I'll be adding unit tests in following days. Please report if you find any issues. If you really need a property, you can now do following: public extension DynamicSubject {
public func asProperty() -> Property<Element> {
let property = Property<Element>(value)
bidirectionalBind(to: property)
return property
}
} |
No apologies necessary at all! I know you're a busy guy and you work very hard to maintain this repository as quickly as possible. I just wanted to extend the offer of help again since I do need to get this for a release version ASAP. These changes sound awesome! Thanks so much! That seems to fix #288, and it does fix the scenario where the object's deallocation was causing the Thanks again |
Ah, conversions... It will crash, but I prefer it that way because 1) you can always make it safer yourself and 2) it makes things easier to work with when everything is expected to be convertible - which I think is at least 90% of time. If the KVO signal would be failable, it would not be bindable. If you expect KVO values that are not convertible, you can do conversion by yourself. Observe KVO values as let name: Signal<String, MyError> = object
.dynamic(keyPath: "test", ofType: Optional<Any>.self)
.tryMap { (value) -> Result<String, MyError> in
if let value = value as? String {
return .success(value)
} else {
return .failure(MyError.conversion)
}
} Thank you for your assistance offer! Problem is that I wasn't sure myself how exactly should this be implement so I had to research a bit first. |
Cool thanks for the info! |
@srdanrasic I'm having trouble depending on the newest beta because it still uses a dependency on |
@AnthonyMDev Just did! |
Thanks! |
@srdanrasic This is still causing me issues when dealing with |
Damn. Let's make it a failable signal as default then. Give me a day, I'll have to refactor DynamicSubject to be failable too. |
@srdanrasic Well, I still understand your original argument that making it failable makes it harder to work with. So, we could consider something else... What if, rather than crashing, no event was emitted if the value is not convertible?
I want to be able to handle errors here, but I also don't think that its a good thing to make it so that |
I saw that version |
Thanks! Actually it did, I forgot to tell you :) This is how KVO interface looks now: public extension NSObject {
public func dynamic<T>(keyPath: String, ofType: T.Type) -> DynamicSubject<NSObject, T>
public func dynamic<T>(keyPath: String, ofExpectedType: T.Type) -> DynamicSubject2<NSObject, T, KVOError>
} If using second method, you get a failable signal ( |
@srdanrasic This looks good, however this is now causing me to be unable to use Thanks! |
Never mind. I figured this out! Thanks so much! |
I don't believe it is proper behavior here for
Bond
to cause my application to crash when anRKKeyValueSignal
gets a change that is not convertible to the signal's type. I would instead like to see the signal send me an error in this case. The user should be able to handle this error as they see fit, rather than having an application crash.I have found this causing many crashes in my application when using
NSManagedObject
s and deallocating multiple view controllers, (i.e. when popping to the root view controller of a navigation stack). This is because I am deallocating the managed object's context simultaneously to the deallocation of the view controllers. The context is set tonil
for the objects and a KVO event is fired with a value ofnil
. The signals, which will be shortly disposed of, but have not been yet, cannot convert thenil
value to the expected type and cause a fatal error.Thoughts?
The text was updated successfully, but these errors were encountered: