2015-10-15 33 views
0

我想通過swift代碼查詢我的AWS Dynamo數據庫表「UserCreds」。我首先定義了一個類,然後將其映射到Dynamo DB表。然後我調用AWSDynamoDBQueryExpression()來搜索此表上的一行。 但節目一直與以下錯誤而崩潰:AWS Dynamo數據庫對象映射器錯誤

「ViewController11viewDidLoadFS0_FT_T_L_11DDBTableRow dynamoDBTableName]:無法識別的選擇發送到類0x102ec3d40]」

我也保證我在AppDelegate的文件正確的憑據設置。任何有關這可能會失敗的原因的深入瞭解將非常感激。謝謝!

下面是代碼的樣子:

進口的UIKit

類的ViewController:UIViewController的{

override func viewDidLoad() { 
    super.viewDidLoad() 


    class DDBTableRow :AWSDynamoDBObjectModel { 

     var UserIdentifier:String? 
     var UserFullName:String? 


     class func dynamoDBTableName() -> String! { 
      return "UserCreds" 
     } 

     class func hashKeyAttribute() -> String! { 
      return "UserIdentifier" 
     } 

     class func rangeKeyAttribute() -> String! { 
      return "UserFullName" 
     } 

     //MARK: NSObjectProtocol hack 
     override func isEqual(object: AnyObject?) -> Bool { 
      return super.isEqual(object) 
     } 

     override func `self`() -> Self { 
      return self 
     } 
    } 


    //SEARCH FOR A ROW 
    let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper() 

    let queryExpression = AWSDynamoDBQueryExpression() 
    queryExpression.indexName = "UserIdentifier-UserFullName-index" 
    queryExpression.hashKeyAttribute = "UserIdentifier" 
    queryExpression.hashKeyValues = "1234" 
    queryExpression.scanIndexForward = true 

    dynamoDBObjectMapper.query(DDBTableRow.self, expression: queryExpression).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task:AWSTask!) -> AnyObject! in 
     if (task.error != nil) { 
      print("Error: \(task.error)") 

      let alertController = UIAlertController(title: "Failed to query a test table.", message: task.error.description, preferredStyle: UIAlertControllerStyle.Alert) 
      let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: { (action:UIAlertAction) -> Void in 
      }) 
      alertController.addAction(okAction) 
      self.presentViewController(alertController, animated: true, completion: nil) 
     } else { 
      if (task.result != nil) { 
       print(task.result) 
      } 
      print("Performing Segue") 
     } 
     return nil 
    }) 

} 
+0

你有直接從應用程序訪問Dynamo而不是通過api使用它的原因嗎?使用api,您可以處理Db交互並將簡單對象返回給您的應用程序。另外,我發現對我的API進行後端更改更容易,而無需向用戶發送新版本。 –

+0

你有解決這個問題嗎? –

回答

0

是否合理有viewDidLoad中內你DDBTableRow類定義()方法中ViewController類?