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

Cell mapping is missing for model #38

Closed
seyhunak opened this issue May 13, 2016 · 6 comments
Closed

Cell mapping is missing for model #38

seyhunak opened this issue May 13, 2016 · 6 comments

Comments

@seyhunak
Copy link

seyhunak commented May 13, 2016

Hello,

I was getting following error.

fatal error: Cell mapping is missing for model: Task(userId: 1, id: 1, title: "delectus aut autem", completed: false)

  {
    "id" : 199,
    "title" : "numquam repellendus a magnam",
    "userId" : 10,
    "completed" : true
  },
  {
    "id" : 200,
    "title" : "ipsam aperiam voluptates qui",
    "userId" : 10,
    "completed" : false
  }
]

Cell mapping is missing for model: Task(userId: 1, id: 1, title: "delectus aut autem", completed: false)
fatal error: Cell mapping is missing for model: Task(userId: 1, id: 1, title: "delectus aut autem", completed: false): file /Users/seyhunak/Projects/DemoTableViewManager/Pods/DTTableViewManager/Source/DTTableViewManager.swift, line 532

Here is the my implementation.

TaskViewController.swift

let json: NSArray? = try response.mapJSON() as? NSArray
   if let json = json {
       let tasks: Array<Task>? = Mapper<Task>().mapArray(json)

       self.manager.memoryStorage.removeAllItems()
       self.manager.memoryStorage.addItems(tasks!, toSection: 0)
       self.tableView.reloadData()                        
}

Task.swift

import Foundation
import ObjectMapper

// MARK: Initializer and Properties

public struct Task: Mappable {

    var userId: Int!
    var id: Int!
    var title: String!
    var completed: Bool!

    // MARK: JSON

    public init?(_ map: Map) {
        mapping(map)
    }

    public mutating func mapping(map: Map) {
        userId <- map["userId"]
        id <- map["id"]
        title <- map["title"]
        completed <- map["completed"]
    }

}

Fyi @DenHeadless

Thanks.

@DenTelezhkin
Copy link
Owner

Hey!

Prior to adding items to storage, you need to call

manager.registerCellClass(YourCellClass)

Where YourCellClass conforms to ModelTransfer protocol, therefore having following method:

class YourCellClass : UITableViewCell, ModelTransfer
{
    func updateWithModel(model: Task) {
    }
}

@Emptyless
Copy link

Emptyless commented Jan 10, 2017

I have the same problem but I did define my cells to have the ModelTransfer and have the new Swift 3 syntax:

func update(with model: String) { self.nameLabel.text = model }

Getting this exact error:

Error Domain=DTTableViewManager.DTTableViewFactoryError Code=1 "(null)"
fatal error: Cell mapping is missing for model: ["Test User 1", "Test User 2"]

@DenTelezhkin
Copy link
Owner

Your model for some reason is an Array of Strings, not String.

@Emptyless
Copy link

I have written a more detailed post on S.O. : link

I am inputting an array of Strings in the manager.memoryStorage.addItems(items) like in the example right? What is/am I doing wrong?

@DenTelezhkin
Copy link
Owner

You should use addItems instead of addItem since you have an array of strings.

You would use addItem in case your model in cell is [String].

@Emptyless
Copy link

Thanks! I must have been reading over the 's' I did not have. Thank you very much.

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

3 participants