Ios DynamoDB保存到DB

Ios DynamoDB保存到DB,ios,xcode,amazon-web-services,amazon-dynamodb,Ios,Xcode,Amazon Web Services,Amazon Dynamodb,我是AWS新手,我正在尝试使用AWS示例with News表将数据保存到我的数据库中 我将此功能连接到主情节提要按钮: @IBAction func addButton(_ sender: Any) { let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default() //Create data object using data models you downloaded from Mobile Hub le

我是AWS新手,我正在尝试使用AWS示例with News表将数据保存到我的数据库中

我将此功能连接到主情节提要按钮:

 @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.")
    })

} 
但当我按下按钮时,我得到:
mazon DynamoDB保存错误:Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain code=0“(null)”UserInfo={{uuuu type=com.amazon.coral.validate}ValidationException,message=Supplied AttributeValue为空,必须正好包含一个受支持的数据类型}

我的新闻字段是:

       override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
    return [
           "_userId" : "userId",
           "_articleId" : "articleId",
           "_author" : "author",
           "_category" : "category",
           "_content" : "content",
           "_title" : "title",
    ]
}

我也遇到了同样的问题,例如,我解决了在News()的每个变量中添加@objc的问题

class News: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
    @objc var id: String?
    @objc var type: String?
    @objc var cc: String?
}

如果您添加@objc强制包装到NS对象,这是aws mobile sdk的一个bug…

关联的dynamoDB表需要哪些字段?这确实帮助了我。向上投票。谢谢