user3353382
user3353382

Reputation: 25

NSMutableDictionary using objectAtIndex

I am new to Xcode and I have created a NSMutableDictionary *dIc with following data:

Keys : ID , Name

Data :

I want to access dIc with specific row. I want this result for example :

Name = Smith.

I tried :

-(void)initiateArrays
{
    dIc =[[NSMutableDictionary alloc] init];
}
- (void)viewDidLoad
{
    [self initiateArrays];
    [self callingWebSrvc];
    [super viewDidLoad];
}
-(void)callingWebSrvc
{

    NSInteger i=0;


    do {
        self.selectedRowId = [[mainMenuID objectAtIndex:i]integerValue];
        [self getItemListFromWebSrvc];
    i++;
    } while (i<= mainMenuData.count - 1);

}
-(void) getItemListFromWebSrvc
{
    //............ Request ....................................>>>
    .
    .
    .
    //............ Response ....................................>>>
    NSInteger i = 0;
    do {
        elm = [xmlDataTable objectAtIndex:i];
        //Set Object into Arrays

        [dIc setObject:[NSNumber numberWithInt:selectedRowId] forKey:@"Id"];
        [dIc setObject:[elm childNamed:@"Name"].value forKey:@"Name"];

        NSArray *keys = [rowArray allKeys];

        // values in foreach loop
        for (NSString *key in keys) {
            NSLog(@"%@ is %@",key, [dIc objectForKey:key ]);
        }

        i=i+1;
    } while (i <= xmlDataTable.count-1);
}
-(void)showResult
{
    NSString *anObject = [[dIc objectForKey:@"Name"  ] objectAtIndex:1];
    NSLog(@"The Value is = %@",anObject );
}

but it's not working.

when i call [self showResult]; i got the following error: -[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x8b9a7f0 2014-02-26 00:53:57.718 iWish[3311:70b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x8b9a7f0'

Upvotes: 0

Views: 173

Answers (1)

matt
matt

Reputation: 534987

The problem is this line:

NSString *anObject = [[dIc objectForKey:@"Name"  ] objectAtIndex:1];

The first object in this story, [dIc objectForKey:@"Name" ], is an NSString. You are then saying objectAtIndex:1 to an NSString - and that is a no-no.

Upvotes: 1

Related Questions