2

I'm trying to load an item from my dynamodb table to my ios app

func fetch() {

dynamoDBObjectMapper.load(Dish.self, hashKey: "001", rangeKey:"01").continueWith(block: { (task:AWSTask<AnyObject>!) -> Any? in
    if let error = task.error as NSError? {
        print("The request failed. Error: \(error)")
    } else if let resultDish = task.result as? Dish {
        // Do something with task.result.
      let cell = DishTableViewCell()
        cell.setDish(dish: resultDish)

    }
    return nil
})

}

my function in called on view did load of my table view.

but when my code reach dynamoDBObjectMapper.load

my log sais : Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_dishNum is not a property of MyFoodApp.Dish.'

that's Dish class

class Dish: AWSDynamoDBObjectModel, AWSDynamoDBModeling {

var _userId: String?
var _dishNum: String?
var _dishDes: String?
var _dishName: String?
var _dishPrice: NSNumber?
var _dishType: String?

class func dynamoDBTableName() -> String {

    return "myfoodapp-mobilehub-XXXXXXXX-dish"
}

class func hashKeyAttribute() -> String {

    return "_userId"
}

class func rangeKeyAttribute() -> String {

    return "_dishNum"
}

override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
    return [
           "_userId" : "userId",
           "_dishNum" : "dish_num",
           "_dishDes" : "dish_des",
           "_dishName" : "dish_name",
           "_dishPrice" : "dish_price",
           "_dishType" : "dish_type",
    ]
}

}

as you can see I have a property called _dishNum so I'm not sure why it crashes.

I also noticed that if in the haskey argument i type a string that does not exist in my table view the app will not crash.

H.Epstein
  • 721
  • 1
  • 7
  • 26

0 Answers0