Closed alonreptor closed 6 years ago
@alonreptor it works quite the same way for SplitRow
. The only difference is, you get a value of type SplitRowValue<L,R>
back, which is a container object holding the values of the embedded rows.
that said, you can access the values like follows:
let row = form.rowBy(tag: "splitRowTag") as? SplitRow<PushRow<String>,DateRow>
let leftValue = row?.value?.left
let rightValue = row?.value?.right
Closing the issue for now. feel free to reopen if it does not work out.
I use SplitRow, I need to obtain values trough self.form.values(), when i do:
let formvalues = self.form.values()
let some_answer = formvalues["ingredients"]
print(some_answer)
i obtain this:
Optional(Optional([Optional(EurekaTest.SplitRowValue<Swift.Int, Swift.String>(left: Optional(1600), right: Optional("Flour"))), Optional(EurekaTest.SplitRowValue<Swift.Int, Swift.String>(left: Optional(360), right: Optional("Water")))]))
How can i get the values L,F for each row?
if i cast
let some_answer = formvalues["ingredients"] as? SplitRow<String,String>
some_answer return nil
@pilloom it looks like you have a value of the type SplitRowValue<Int, String>
. Try:
let some_answer = formvalues["ingredients"] as? SplitRowValue<Int, String>
print("leftValue:", some_answer?.left, "rightValue:", some_answer?.right)
@marbetschar Could you please give me an advice. I can't get the values from my SplitRow. My form:
MultivaluedSection(multivaluedOptions: [.Insert, .Delete],
header: "Language you want to learn",
footer: "Select language and level") {
$0.tag = "want_to_learn_languages"
$0.multivaluedRowToInsertAt = { index in
return SplitRow<ActionSheetRow<String>, ActionSheetRow<String>>(){
$0.rowLeft = ActionSheetRow<String>(){
$0.options = ["English", "Spanish", "Portuguese", "Chinese", "German", "French", "Italian"]
}
$0.rowRight = ActionSheetRow<String>(){
$0.options = ["Beginner", "Intermediate", "Fluent"]
}
}
}
$0 <<< SplitRow<ActionSheetRow<String>, ActionSheetRow<String>>(){
$0.rowLeft = ActionSheetRow<String>(){
$0.options = ["English", "Spanish", "Portuguese", "Chinese", "German", "French", "Italian"]
}
$0.rowRight = ActionSheetRow<String>(){
$0.title = "Select level"
$0.options = ["Beginner", "Intermediate", "Fluent"]
}
}
}
This : var values = self.form.values() let result = values["want_to_learn_languages"]
Return:
Optional(Optional([Optional(SplitRow.SplitRowValue<Swift.String, Swift.String>(left: Optional("German"), right: Optional("Beginner"))), Optional(SplitRow.SplitRowValue<Swift.String, Swift.String>(left: Optional("German"), right: Optional("Beginner")))]))
But i can't unwrap it in any ways.
I tried: let result = values["want_to_learn_languages"] as? SplitRowValue<String, String>
let result = values["want_to_learn_languages"] as? SplitRow<ActionSheetRow
let result = values["want_to_learn_languages"] as? SplitRowValue<ActionSheetRow
and some more, but everytime i get nil
@masliev I assume you are running into issues because of the MultivaluedSection
. Therefore the values["want_to_learn_languages"]
may contain multiple rows - and therefore values. Or in other words, I think you should expect an array there.
That said, try the following (untested):
let result = values["want_to_learn_languages"] as? [SplitRowValue<ActionSheetRow<String>, ActionSheetRow<String>>]
UPDATE: A closer look at your print does indeed return an array - it's just not that easy to see:
Optional(Optional(
[
Optional(SplitRow.SplitRowValue<Swift.String, Swift.String>(left: Optional("German"), right: Optional("Beginner"))), Optional(SplitRow.SplitRowValue<Swift.String, Swift.String>(left: Optional("German"), right: Optional("Beginner")))
]
))
From reading that output more carefully, it should work like this:
let result = values["want_to_learn_languages"] as? [SplitRowValue<String, String>]
@marbetschar Many thanks sir, it works perfectly!!! Also thank you for the quick response.
how can we get Split row left and right values dynamically without specifying Left and Rights types (SplitRowValue<String,Double>).
For example if i have 5 different rows of split rows (which means total form items would be 10) so how can i get values of each row in 'String?'. Currently I have to iterate over all 5 rows and check all possible combinations for SplitRowValues like SplitRowValue<Double, Double>, SplitRowValue<String, Double>, SplitRowValue<Double, String> and so on.
If I understand your question correct, then the short answer is: You can't.
That's how static typed languages such as Swift work by design: You need to provide the type at compile time and if you want to convert a Double to a String, you need to tell the compiler how to do that.
So from the compilers point of view, each of the following represents a unique type - and there is no such thing such as a "subpart of a type":
Double
Double?
String
String?
SplitRow<Double, String>
SplitRow<String, String>
For Eureka rows:
but i cant get it for SplitRow
Please advise