我正在尝试将 dynamodb 表中的项目加载到我的 ios 应用程序
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
})
}
view did load
我的表视图中调用了我的函数。
但是当我的代码到达dynamoDBObjectMapper.load
我的日志是:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_dishNum is not a property of MyFoodApp.Dish.'
那是菜课
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"
}
类 func rangeKeyAttribute() -> 字符串 {
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",
]
}
}
如您所见,我有一个名为 _dishNum 的属性,所以我不确定它为什么会崩溃。
我还注意到,如果在 haskey 参数中我输入了一个在我的表格视图中不存在的字符串,则应用程序不会崩溃。