Add setStringValue:forExpression method on UIView#186
Add setStringValue:forExpression method on UIView#186cadrega wants to merge 2 commits intonicklockwood:developfrom
Conversation
The setStringValue:forExpression method on UIView can set any value from a string, just like Layout does when looking at the XML attributes for a View. This expands the possibilities of the setValue:forExpression, which needs the value to be of the right type.
nicklockwood
left a comment
There was a problem hiding this comment.
A few style issues with the code, but otherwise seems reasonable.
Layout/UIView+Layout.swift
Outdated
| if let typ = type(of: self).cachedExpressionTypes[name] { | ||
| if let node = _layoutNode { | ||
| if let exp = LayoutExpression(expression: value, type: typ, for:node) { | ||
| if let res = try? exp.evaluate() { |
There was a problem hiding this comment.
The setStringValue is marked as throwing, but all the errors are suppressed using try? - was that intentional?
There was a problem hiding this comment.
I initially copied the method signature of the other setValue, and so kept the throwing attribute.
For my project, I didn't really care about any error - set it or fail silently.
For the general use case, maybe it should be best for the errors to bubble up. (Although I don't know what can be done with the error, outside of this class... Maybe logging it?)
There was a problem hiding this comment.
OK, I thought about it and it should be good to bubble up errors that happen during expression evaluation and newvalue setting.
Fix indenting style (spaces, not tabs) Remove the "if pyramid of doom" by combining all let statements into a single guard Don't suppress errors while evaluating the expression or setting the value
|
I updated the branch, addressing your comments. Is that the right thing to do, or should I create a new pull request? |
|
Using this mod on Layout, I noticed two things:
By "not working" I mean the method has been called but no visible effect was achieved, and no error was spit out. |
The setStringValue:forExpression method on UIView can set any value from a string, just like Layout does when looking at the XML attributes for a View. This expands the possibilities of the setValue:forExpression, which needs the value to be of the right type.