1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iosアプリからのdynamoDBスキャンができない

Last updated at Posted at 2019-03-06

ややハマりしたので、備忘録
曖昧な理解のまま、この記事を書いてますので、誤り等あればご指摘ください。

#dynamoDBの公式のドキュメントどおりに記述してもスキャンできない

公式のドキュメント↓ 古いのかな?いつのものか確認出来てないです。ごめんなさい。
https://docs.aws.amazon.com/ja_jp/aws-mobile/latest/developerguide/how-to-ios-dynamodb-objectmapper.html#perform-a-scan

公式によると

 let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default()
 let scanExpression = AWSDynamoDBScanExpression()
 scanExpression.limit = 20

dynamoDBObjectMapper.scan(Book.self, expression: scanExpression).continueWith(block: { (task:AWSTask<AnyObject>!) -> Any? in
     if let error = task.error as? NSError {
         print("The request failed. Error: \(error)")
     } else if let paginatedOutput = task.result {
         for book in paginatedOutput.items as! Book {
             // Do something with book.
         }
     }
 })

となっているのですが、コンパイルエラー

scanメソットは、AWSDynamoDBPaginatedOutput型 をもらってくるらしいので、下記で動きました。

 let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default()
 let scanExpression = AWSDynamoDBScanExpression()
 scanExpression.limit = 20

dynamoDBObjectMapper.scan(Book.self, expression: scanExpression).continueWith(block: { (task:AWSTask<AWSDynamoDBPaginatedOutput>!) -> Any? in
     if let error = task.error as? NSError {
         print("The request failed. Error: \(error)")
     } else if let paginatedOutput = task.result {
         for book in paginatedOutput.items{
             // Do something with book.
             print(book)
         }
     }
 })


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?