froggomad
froggomad

Reputation: 1915

NSInternalInconsistencyException _variable is not a property of projectName.Classname

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

Upvotes: 0

Views: 207

Answers (2)

froggomad
froggomad

Reputation: 1915

It turns out the AWS SDK isn't exactly Swift 4 compatible yet. In swift 4, you have to put @objcMembers before the object model class definition like:

    @objcMembers class Article: AWSDynamoDBObjectModel, AWSDynamoDBModeling { 

}

Upvotes: 0

gmogames
gmogames

Reputation: 3081

Check to see if datePublished is a String or Date type in the database. If the types do not match, then you will have an error.

Upvotes: 1

Related Questions