Reputation: 731
I'm new to AWS and i'm trying to save data to my database using the aws example with News table.
I connected this function to the main storyboard button :
@IBAction func addButton(_ sender: Any) {
let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()
//Create data object using data models you downloaded from Mobile Hub
let newsItem: News = News();
// Use AWSIdentityManager.default().identityId here to get the user identity id.
newsItem._userId = "us-east-1:74c8f7ce-244b-4476-963e-0dcb3216f406"
newsItem._articleId = "0123"
newsItem._title = "Banana"
newsItem._author = "Logan"
newsItem._content = "Should I stay or should I go now?"
newsItem._category = "Food"
//Save a new item
dynamoDbObjectMapper.save(newsItem, completionHandler: {
(error: Error?) -> Void in
if let error = error {
print("Amazon DynamoDB Save Error: \(error)")
return
}
print("An item was saved.")
})
}
but when I hit the button I get :
mazon DynamoDB Save Error: Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=0 "(null)" UserInfo={__type=com.amazon.coral.validate#ValidationException, message=Supplied AttributeValue is empty, must contain exactly one of the supported datatypes}
my News fields are :
override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
return [
"_userId" : "userId",
"_articleId" : "articleId",
"_author" : "author",
"_category" : "category",
"_content" : "content",
"_title" : "title",
]
}
Upvotes: 2
Views: 523
Reputation: 46
I had the same problem, and I solved adding @objc in eery variable from News(), for example
class News: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
@objc var id: String?
@objc var type: String?
@objc var cc: String?
}
If you add @objc that force to wrap to NS Object, this is a bug for the aws mobile sdk...
Upvotes: 3