我正在尝试使用DynamoDB表,并已成功连接到该表,但无法读取它。当我尝试时,我得到以下错误:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“\u datePublished不是ProjectName.Article的属性。”
这是我的文章类/模型:
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",
]
}
}
我调用的函数
ViewDidLoad
从数据库中读取一篇文章: 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)")
})
}
我做错什么了?DATE发布在DB上的条目中,并在模型中定义
最佳答案
检查datePublished是否是数据库中的字符串或日期类型。如果类型不匹配,则会出现错误。
关于swift - NSInternalInconsistencyExceptionException _variable不是projectName.Classname的属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49395869/