Reputation: 4122
I have a struct/model that I store some JSON data to fill my tableview:
import SwiftyJSON
struct MyData {
let valOne: Int
let valTwo: String
let valThree: Int
init(json: JSON) {
valOne = json["some_data"].intValue
valTwo = json["auc_data"].stringValue
valThree = json["auc_data"].intValue
}
}
Then in my tableview I have a custom cell class that I use when I write out my data:
let data = MyData[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell") as! CustomTableViewCell
cell.configureCellWithData(data)
What I want to do is to pass the struct as a parameter to the configureCellWithData() but I am not sure how to declare it.
Instead of doing something like:
func configureCellWithData(dataOne: Int, dataTwo: String, dataThree: Int) {
}
then
configureCellWithData(data.valOne,data.valTwo,data.valThree)
I dont want to have many parameters instead I want to send the struct right away
Upvotes: 2
Views: 6728
Reputation: 548
Try this.
func configureCellWith(data: MyData) {
// Do stuff here
}
Upvotes: 5