Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind Observable Model of ObjectMapper class with TableView #678

Open
prgorasiya opened this issue Mar 23, 2020 · 7 comments
Open

Bind Observable Model of ObjectMapper class with TableView #678

prgorasiya opened this issue Mar 23, 2020 · 7 comments

Comments

@prgorasiya
Copy link

prgorasiya commented Mar 23, 2020

I have defined custom model as an Observable.

Here is my Model

import ObjectMapper
struct DetailsV2Model: Mappable {
    var status: StatusWithTimeModel!
    var location: LocationModel!
    
    mutating func mapping(map: Map) {
        status <- map["status"]
        location <- map["startLocation"]
    }
    
    
    init?(map: Map) {
        
    }
}

ViewModal class

class DetailsContainerViewModal {
    var detailsModel = Observable<DetailsV2Model>(DetailsV2Model(map: Map(mappingType: .fromJSON, JSON: [:]))!)
}

I can define instance of DetailsV2Model as above.
However, I am stuck at binding it with tableView.

viewModel?.detailsModel.bind(to: self.tableView) { (tableView, model) in

}

I can't get IndexPath with above binding, which I need to load appropriate cell.

How should I solve this issue?

@prgorasiya
Copy link
Author

Any feedback on this?

@srdanrasic
Copy link
Contributor

Are you sure that is a Bond related question @prgorasiya.

@prgorasiya
Copy link
Author

Yes, i want to bind my model to table view.
The model is of Mappable because I am using ObjectMapper.
Therefore I am unable to define my model as Observable and bind it to table view.
Any idea how can I achieve that? Or any alternative approach?

@prgorasiya prgorasiya changed the title How to use Observable with ObjectMapper instance Bind Observable Model of ObjectMapper class with TableView Apr 15, 2020
@prgorasiya
Copy link
Author

I was able to solve the previous issue at some extent.
However I am stuck at next stage which is Binding.
I have updated my question.
Any help would be much appreciated.
Thanks

@srdanrasic
Copy link
Contributor

@prgorasiya there is a bind(to:) overload that gives you the index path:

https://github.com/DeclarativeHub/Bond/blob/master/Sources/Bond/UIKit/UITableView%2BDataSource.swift#L41

@prgorasiya
Copy link
Author

prgorasiya commented Apr 17, 2020

Thanks @srdanrasic
I am aware of it and using it elsewhere in my project.
However current implementation has multiple tableView cells and I have single datasource model of DetailsV2Model(Not array) which holds 2 properties of StatusWithTimeModel and LocationModel.
I guess that overload function may not be useful in my case as its useful when bind with Array datasource. Am I right?

@prgorasiya
Copy link
Author

@srdanrasic Appreciate if you could provide any pointers here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants