Create Binding+Validation.swift - #1
Conversation
mkj-is
left a comment
There was a problem hiding this comment.
Thanks for the contribution, I added one comment regarding the return type. What do you think?
|
Good point, we probably only need the bool version and I will return false when I call a throwing func that fails. |
|
E.g. so now I can do: |
|
Maybe now it should be renamed filter? |
I am fine with |
|
I thought I'd share something interesting I noticed about TextField's value binding when using a computed Binding. Say you have "1" in the TextField and you select all and paste "2A" the binding setter is called with 2. If you had however pasted "A2" then the binding is set with 1, i.e. the old value. This makes me wonder if we should be setting the wrapped value to the original value when validation fails? Edit: seems to me TextField's value behaviour has not been implemented correctly. If the parsing fails it should set nil on an optional but it actually resets the last valid value. This means the textfield goes out of sync with the model, i.e. a save button might be enabled because the model's values are valid yet the textfield contains junk! |
No description provided.