0

i just started out working on a project using Amazon Web Services SimpleDB. in one method i am trying to figure out how many items a domain already contains by using a select query.

The code looks like this:

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];

This works just fine. eg: the connection works, and the response seems to be right as well when i log it:

{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}}}

What i want to do next, is to save the value2 into an NSInteger itemCount. Here is where i struggle. I tried several things, the furthest i came was:

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

which should work in my eyes. but it throws the error:

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

Can anyone point out to me where i went wrong? I am truly stuck here.

Thanks, Sebastian

Sebastian Flückiger
  • 5,525
  • 8
  • 33
  • 69
  • I would suggest breaking that bracketed line into individual parts. I'm suspicious of the call to value. I think I would first get the attributes array, then get the object for the key:"Value", make sure it's an NSNumber and then get the intValue. – geraldWilliam Oct 31 '12 at 22:37
  • But if you break it into parts like that then it will be easier to identify where it breaks down. – geraldWilliam Oct 31 '12 at 22:38
  • These link also describe about this error. Please see and may resolve your issue - http://stackoverflow.com/questions/7770872/deep-copy-of-dictionaries-gives-analyze-error-in-xcode-4-2 http://stackoverflow.com/questions/12434167/cant-build-in-x-code-4-5-because-of-multiple-methods-named-error – Ashish Pancholi Nov 01 '12 at 05:28
  • i'll try that and get back here :) – Sebastian Flückiger Nov 01 '12 at 13:21

1 Answers1

2

Thanks to the comment of geraldWilliam i figured it out:

    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];
        }
    }

This approach works.

Sebastian Flückiger
  • 5,525
  • 8
  • 33
  • 69