Hi, it would be amazing if we can pass a custom object to a row. It could be a NSObject. This could be used for multiple purposes (My goal is to hold a reference when i'm editing an object instead of adding an new).
@sagits Could you elaborate more on what you are trying to accomplish?
Hi, i have done it on my local version, i have added a property named object on all my rows.
I will give an example, i have a customer model, which has:
id : int, name : String, phoneList : [phoneModel]
And phoneModel has:
id : int, number : String, type : String
Now i`m editing a customer that has 4 phones, for each phone i will create two fields (number and type). Now on my form, i have a button "add phone", this button add 2 more fields (for a new number and type). For now i have just the forms, the customer with its phones will be saved when i click on "save".
The problem is that later, when i save my customer, i have phones that need to be edited (i have to look up my customerModel.phoneList for this phone and change its number or type based on what user typed) and phones that need to be created (the user clicked on addphone).
I need a way to link the phoneModels that already exist (they already have an object with an id) with their respective forms, while preserving the forms that are linked to new phones.
Them i doing something like:
if (row.object != nil) {
for phone in customer.phones {
if (phone.id == row.object.id) {
var newPhone : PhoneModel = PhoneModel()
// add the row values to number and type
newPhone.id = row.object.id
phone = newPhone //change the object in my list to the new one while preserving the id
break;
}
else {
var newPhone : PhoneModel = PhoneModel()
// add the row values to number and type
customer.phones.add(newPhone)
}
}
}
We believe this can be done by setting the value of the row to be your object and using the displayValueFor block to customize what will be shown on the cell.
Most rows of Eureka are generic so you could define this:
let row = WhateverRow<PhoneModel>(){
$0.displayValueFor = { value in
return value.number
}
}
If this does not work, you can still override a row to have a object property.
I think this is something to be done project-wise. We could add a simple var extraData: AnyObject? but you would certainly want this to be strongly typed ( possibly with a different type per row type).
Therefore I suggest that the value of the row should be the object or an equatable wrapper of that object or subclass an existing row to add this property. The latter option can be done easily with most rows as they have a superclass that includes most of the logic.
For example:
public final class MyPushRow<T: Equatable> : _PushRow<T, PushSelectorCell<T>>, RowType {
var object: AnyObject!
public required init(tag: String?) {
super.init(tag: tag)
}
}
Most helpful comment
We believe this can be done by setting the value of the row to be your object and using the
displayValueForblock to customize what will be shown on the cell.Most rows of Eureka are generic so you could define this:
If this does not work, you can still override a row to have a object property.