ios - DynamoDB 保存到数据库
<p><p>我是 AWS 的新手,我正在尝试使用带有 News 表的 aws 示例将数据保存到我的数据库中。 </p>
<p>我将此功能连接到主 Storyboard 按钮:</p>
<pre><code> @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.")
})
}
</code></pre>
<p>但是当我按下按钮时,我得到:
<code>mazon DynamoDB 保存错误:Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=0 "(null)"UserInfo={__type=com.amazon.coral.validate#ValidationException, message=Supplied AttributeValue 为空,必须只包含一个支持的数据类型}</code></p>
<p>我的新闻字段是:</p>
<pre><code> override class func jsonKeyPathsByPropertyKey() -> {
return [
"_userId" : "userId",
"_articleId" : "articleId",
"_author" : "author",
"_category" : "category",
"_content" : "content",
"_title" : "title",
]
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我遇到了同样的问题,例如,我解决了在 News() 的怪异变量中添加 @objc 的问题</p>
<pre><code>class News: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
@objc var id: String?
@objc var type: String?
@objc var cc: String?
}
</code></pre>
<p>如果您添加 @objc 强制包装到 NS 对象,这是 aws mobile sdk 的错误...</p></p>
<p style="font-size: 20px;">关于ios - DynamoDB 保存到数据库,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46776381/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46776381/
</a>
</p>
页:
[1]