我刚刚开始使用Amazon Web Services SimpleDB进行项目。
在一种方法中,我试图通过使用select query来计算域中已经包含了多少项。

代码如下:

AmazonSimpleDBClient *dbClienet = [[AmazonSimpleDBClient alloc]initWithAccessKey:_secret withSecretKey:_hiddenSecret];
NSString *countRequestString = [NSString stringWithFormat:@"select count(*) from %@",domain];
SimpleDBSelectRequest *countRequest = [[SimpleDBSelectRequest alloc]initWithSelectExpression:countRequestString];
SimpleDBSelectResponse *countResponse = [dbClienet select:countRequest];


这很好。例如:连接有效,当我登录时响应似乎也正确:

{Items: (
"{Name: Domain,AlternateNameEncoding: (null),Attributes: (\n    \
"{Name: Count,AlternateNameEncoding: (null),Value: 2,AlternateValueEncoding: (null),<SimpleDBAttribute: 0x756f730>}\"\n),<SimpleDBItem: 0x7529d00>}"),NextToken: (null),{BoxUsage: 0.000023,{requestId: b683ed01-9e5f-9041-1ace-cbb0fdfaa799}}}


我接下来要做的是将值2保存到NSInteger itemCount中。这是我奋斗的地方。
我尝试了几件事,最远的是:

NSInteger itemCount = [[[[[countResponse.items objectAtIndex:0]attributes]objectAtIndex:1]value]integerValue];


应该在我眼中起作用。但它抛出错误:

Multiple methods named 'value' found with mismatched result, parameter type or attributes


谁能指出我哪里出问题了?我真的被困在这里。

谢谢塞巴斯蒂安

最佳答案

多亏了geraldWilliam的评论,我才知道:

    NSString *countRequestString = [NSString stringWithFormat:@"select count(*) from %@",domain];
    SimpleDBSelectRequest *countRequest = [[SimpleDBSelectRequest alloc]initWithSelectExpression:countRequestString];
    SimpleDBSelectResponse *countResponse = [dbClienet select:countRequest];
    NSArray* attributes = [[countResponse.items objectAtIndex:0]attributes];
    for (SimpleDBAttribute*attr in attributes) {
        if ([attr.name isEqualToString:@"Count"]) {
            itemCount = [attr.value integerValue];
        }
    }


这种方法有效。

关于objective-c - AWS iOS SDK simpleDB项数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13167720/

10-11 06:40