Closed primeviltom closed 4 years ago
Hi @primeviltom,
The SplitRowValue
is actually a struct, containing the fields left
and right
which in turn contain the actual leftRow
and rightRow
values.
That said, you should be able to access the desired values with something like this (pseudo code):
let splitRowValue = xyz as? SplitRow<SwitchRow, DecimalRow>
// value of rowLeft:
print(splitRowValue?.left)
// value of rowRight:
print(splitRowValue?.right)
I'll close this issue for now. Feel free to reopen if you see fit.
EDIT: added ?
after splitRowValue
because its an Optional
.
Thanks for your reply, however I'm still unable to get a value out. The auto-complete shows that I should be getting a Bool or Double from the value I'm after. i.e. https://i.imgur.com/th58ydP.png
However, this code:
let splitRowValue = formValues["splitRowPrice"] as? SplitRow<SwitchRow, DecimalRow>
print(splitRowValue?.rowLeft?.value)
print(splitRowValue?.rowRight?.value)
Still generates nils in the console (formatted for readability):
[
"postDescription": Optional("Wef"),
"splitRowURL": Optional(SplitRow.SplitRowValue<Swift.Bool, Swift.String>(left: Optional(false), right: nil)),
"splitRowPrice": Optional(SplitRow.SplitRowValue<Swift.Bool, Swift.Double>(left: Optional(true), right: Optional(9.99))),
"splitLocation": Optional(SplitRow.SplitRowValue<Swift.Bool, __C.CLLocation>(left: Optional(true), right: Optional(<-28.63381450,+153.63690625> +/- 0.00m (speed -1.00 mps / course -1.00) @ 12/17/19, 6:27:40 AM Australian Eastern Daylight Time))),
"postAs": Optional("The Byron List"),
"splitEvent": Optional(SplitRow.SplitRowValue<Swift.Bool, Swift.String>(left: Optional(false), right: nil)),
"saveButton": nil,
"title": Optional("Wef")
]
nil
nil
@primeviltom it should be splitRowValue?.left
instead of splitRowValue?.rowLeft?.value
- and same thing for the right value ;)
Thanks again for the reply.
Using splitRowValue?.left
gives me a Value of type 'SplitRow<SwitchRow, DecimalRow>' has no member 'left'
error and I can't build: https://i.imgur.com/wysr9es.png
formValues comes from self?.form.values() when the user taps a ButtonRow. I'm not sure where I'm going wrong..
You have to levels of "values" coming into play:
The value type of the SplitRow is a struct of type SplitRowValue
which contains a left
and a right
property, which do hold the values of the embedded rows.
To access the SplitRow's value you want to do something like this:
let splitRowValue = row.value // this returns a value of something like SplitRowValue<Bool, Double>
But to actually access the values of left and right row, you want to do something like this:
let leftValue = row.value?.left // Bool
let rightValue = row.value?.right // Double
If that still does not work, I suggest you'll have another look on how to retrieve a value from a row in the Eureka documentation.
UPDATE: as for your cast in your screenshot, you probably want to cast it to SplitRowValue
instead of SplitRow
, since form.values()
actually returns all row.value
fields of the form - which in case of SplitRow holds the struct SplitRowValue
(see above).
UPDATE 2: Just seen my previous comment was a bit missleading, since it did not contain proper code. Seems like it was already too late for me 🤣 - however, this description here should be correct and get you going.
Finally got it, by casting to SplitRowValue
, not SplitRow
!
Thank you very much 😀🤙
Hi there,
I've decided to utilize splitRow in a project so some fields can be optional, so I am using splitRow with a <SwitchRow, DecimalRow> for example.
I want to parse the entire form when the user has submitted, however I'm having trouble getting data from the SplitRow's like I normally would in a non split-row.
My form looks like: https://i.imgur.com/jUS8lWg.png
When I print out the form data to the console, it looks like:
and this code:
will print out the splitRowPrice as:
Optional(Optional(SplitRow.SplitRowValue<Swift.Bool, Swift.Double>(left: Optional(true), right: Optional(242.34))))
I just don't know how exactly I get the the left and right values!! Casting as a
SplitRow<SwitchRow, DecimalRow>
and variations will give me a nil value, and I'm just not sure exactly how to get the values from the form. Please help!Thanks.