Eureka: MultipleSelectorRow set displayValue based on realm objects

Created on 12 Nov 2016  路  8Comments  路  Source: xmartlabs/Eureka

Before submitting issues ...

  • Make sure you are using Eureka latest release or master branch version.
  • Make sure your Xcode version is the latest stable one.
  • Check if the issue was already reported or fixed. We add labels to each issue in order to easily find related issues. If you found a match add a brief comment "I have the same problem" or "+1".

When submitting issues, please provide the following information to help maintainers to fix the problem faster:

  • Environment: Eureka, Xcode and iOS version you are using.
  • In case of reporting errors, provide Xcode console output of stack trace or code compilation error.
  • Any other additional detail such as your eureka form/section/row code that you think it would be useful to understand and solve the problem.
MultipleSelectorRow

Most helpful comment

What I see in your code is that the options might change but the type of the value should not change. Also you are not using anything specific to another row in your displayValueFor code.

Anyway, alternatively you can make Ladder conform to CustomStringConvertible and return its name as description.

All 8 comments

i'm trying to set the value based to name in a realm object however it keep showing Ladder { as text in cell instead of the name. here is my code

    <<< MultipleSelectorRow<Ladder>("Rank") {
           $0.hidden = Condition.predicate(NSPredicate(format: "$Game == nil"))
           $0.title = $0.tag


           }.cellUpdate { cell, row in

               let formvalues = self.form.values()
               let game = formvalues["Game"] as! Game
               let ranks = Array(game.ranks)
               row.options = ranks
               row.displayValueFor = { (rowValue: Set<Ladder>?) in
                   return rowValue?.map({ $0.name }).sorted().joined(separator: ", ")
               }


               cell.textLabel?.font = UIFont(name: "Avenir-Book", size: 16)

               cell.preservesSuperviewLayoutMargins = false
               cell.separatorInset = UIEdgeInsets.zero
               cell.layoutMargins = UIEdgeInsets.zero

       }

realm model

class Ladder: Object {

    dynamic var id = ""
    dynamic var name = ""

    override static func primaryKey() -> String? {
        return "id"
    }

}

First of all, displayValueFor should be defined in the row initializer and not in cellUpdate as it does not change, right?

That might fix your issue.

i've put in cellUpdate since the value change depending on another rows value.

What I see in your code is that the options might change but the type of the value should not change. Also you are not using anything specific to another row in your displayValueFor code.

Anyway, alternatively you can make Ladder conform to CustomStringConvertible and return its name as description.

i've tried that however this will only return the description in the formValues where i need id in the ladder model to pass to the server.

It will not only return the description but the value itself. But if you print formValues then Xcode will print the description for the Ladder object

Yes i know it will, but what i want is it to print the object itself in formValues, so i can access other values in the object like the primary key, in order to pass something to the server.

row.value type is Ladder, from there you can map the value and get either the id or the name.

Was this page helpful?
0 / 5 - 0 ratings