1

I followed these documents to set up a simple app using dynamoDB: https://docs.aws.amazon.com/aws-mobile/latest/developerguide/add-aws-mobile-nosql-database.html and https://docs.aws.amazon.com/aws-mobile/latest/developerguide/getting-started.html#add-aws-mobile-sdk-basic-setup

And then as a test I used the code provided to Create (Save) an Item.

Once ready to run the app, I get this error message:

Amazon 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}

After searching the net, I discovered there was a problem related to Swift 4. And the solution seems to be adding @objcMembers in front of the classes automatically generated by AWS.

But for me it did not work. The error stays the same. I also tried to set the swift version to 3.3 instead of 4.1 (I only have these 2 versions available), this also did not fix the issue.

Any idea on how to solve the issue?

Michel
  • 10,303
  • 17
  • 82
  • 179
  • Hi @Michel, Did you try adding the objc annotation at the class level or attribute level? Can you try both the methods described in the solution in the issue github.com/aws/aws-sdk-ios/issues/750? Also, have you downloaded the models from AWS Mobile Hub? – Karthikeyan Apr 26 '18 at 21:51
  • Yes I did all that and it did not work (I suppose something else was wrong). I gave up and went to find some other examples on AWS to get started (DynamoDBSampleSwift inside aws-sdk-ios-samples-master) and this time it is finally working. Thanks anyway! – Michel Apr 27 '18 at 00:54
  • Thank you! Can you share what worked and what you think was the error? – Karthikeyan Apr 27 '18 at 01:36
  • I just added an answer, please have a look. – Michel Apr 27 '18 at 02:00

3 Answers3

3

For anyone who runs into this in the future, if you are using Swift 4 and have downloaded the swift models from the AWS Mobile Hub, following the guide then add the @objcMembers on top of the class definition line as shown below. This worked for me.

import AWSDynamoDB

@objcMembers
class TableName: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
Victor 'Chris' Cabral
  • 2,135
  • 1
  • 16
  • 33
1

Here what I did to finally have something working and get started using dynamoDB:

I got this from GitHub.

Then I chose the DynamoDBSampleSwift project inside the archive. I was able to make it work without to much trouble.

I have no idea what was not working in my previous trial.

Michel
  • 10,303
  • 17
  • 82
  • 179
0

I tried so many things but finally, this worked. Add the @objcMembers on top of the class definition line as shown below.

import AWSDynamoDB

@objcMembers
class TableName: AWSDynamoDBObjectModel, AWSDynamoDBModeling {

Thanks, Victor 'Chris' Cabral

Naing Lin Aung
  • 3,373
  • 4
  • 31
  • 48