I'm trying to work with a DynamoDB table, and have successfully connected to it, but am unable to read it. When I try, I get the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_datePublished is not a property of ProjectName.Article.'
Here's my Article class/model:
class Article: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
var _articleSource: String?
var _articleUrl: String?
var _datePublished: String?
var _headline: String?
var _imageURL: String?
var _rating: String?
var _listingId: String?
class func dynamoDBTableName() -> String {
return "tableName"
}
class func hashKeyAttribute() -> String {
return "_listingId"
}
class func rangeKeyAttribute() -> String {
return "_articleUrl"
}
override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
return [
"_articleSource" : "articleSource",
"_articleUrl" : "articleUrl",
"_datePublished" : "datePublished",
"_headline" : "headline",
"_imageURL" : "imageURL",
"_rating" : "rating",
"_listingId" : "listingId",
]
}
}
And the function I'm calling in ViewDidLoad to read an article from the DB:
func readArticle() {
let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()
// Create data object
let article: Article = Article();
dynamoDbObjectMapper.load(
Article.self,
hashKey: "2018-03-17T08:50:30+00:00",
rangeKey: "https://www.example.com",
completionHandler: {
(objectModel: AWSDynamoDBObjectModel?, error: Error?) -> Void in
if let error = error {
print("Amazon DynamoDB Read Error: \(error)")
return
}
print("Article:\n \(article)")
})
}
What am I doing wrong? datePublished exists in that entry on the DB, and is defined in the model