Swift - 传递DynamoDB Paginated Output结果在另一个类中运行

时间:2015-02-02 00:28:11

标签: ios swift amazon-web-services

我试图将我的Amazon.swift'AWS'类中的DynamoDB功能设置的结果传递回我的ViewController。目的是使用数据在地图上创建GPS点(ViewController具有完整的MapKit / mapView设置)。

这是DynamoDB功能:

func read_multipin_data() -> AWSDynamoDBPaginatedOutput { 

    let cond = AWSDynamoDBCondition()
    let v1   = AWSDynamoDBAttributeValue(); v1.S = ADate
    cond.comparisonOperator = AWSDynamoDBComparisonOperator.EQ
    cond.attributeValueList = [ v1 ]

    let exp = AWSDynamoDBScanExpression()
    exp.scanFilter = [ "date" : cond ]

    self.scan(exp).continueWithSuccessBlock({ (task: BFTask!) -> BFTask! in
        let results = task.result as AWSDynamoDBPaginatedOutput
        return results // Error: 'AWSDynamoDBPaginatedOutput' is not convertible to 'BFTask'
    })
}

    func scan(expression : AWSDynamoDBScanExpression) -> BFTask! {

        let mapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()
        return mapper.scan(AWS.self, expression: expression)
    }

目前仅尝试恢复ViewController中数据的第二个函数是:

    @IBAction func refresh_db_pins(){

    let all_annotations_in: AWSDynamoDBPaginatedOutput = AWS().read_multipin_data()   

    }

我尝试返回结果时收到的错误是: 'AWSDynamoDBPaginatedOutput'无法转换为'BFTask'

我尝试了很多不同的方法,包括将JSON格式的数据转换为数组,字典,唉没什么用。

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以将read_multipin_data方法重写为:

func read_multipin_data() -> BFTask {

    let cond = AWSDynamoDBCondition()
    let v1   = AWSDynamoDBAttributeValue()
    v1.S = ADate
    cond.comparisonOperator = AWSDynamoDBComparisonOperator.EQ
    cond.attributeValueList = [ v1 ]

    let exp = AWSDynamoDBScanExpression()
    exp.scanFilter = [ "date" : cond ]

    return self.scan(exp);
}

continueWithSuccessBlock内,您需要返回BFTasknil的实例,但是您要返回AWSDynamoDBPaginatedOutput的实例。这就是编译器抱怨的原因。