bruno
bruno

Reputation: 2169

Error setting value of NSMutableDictionary

I initialize this NSMutableDictionary:

define TAREFA      @"TAREFA"  
define DATA_ITEM        @"DATA"   
define HORA_ITEM        @"HORAS"  
define ID          @"ID"  
define STATE       @"NA"  
define APROVED     @"APROVED"  
define REJECTED    @"REJECTED" 

    itensArray = [[NSMutableArray alloc] init];

    for (int i=0; i< [listagens size]; i++)
    {   
        NSMutableDictionary *tmpDictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                        [[listagens item:i] WI_ID], ID,
                                        [[listagens item:i] WI_TEXT], TAREFA,
                                        [[listagens item:i] WI_CD], DATA_ITEM,                                            
                                        [[listagens item:i] WI_CT], HORA_ITEM,                                                                                     
                                        STATE, STATE,
                                        nil];

        [itensArray addObject:tmpDictionary];           
    }

Later on, i do the following:

    for (int i=0; i<[itensArray count]; i++) 
    {
        if ([[[itensArray objectAtIndex:i] objectForKey:ID] isEqualToString:cell.idLabel.text]) {
            [[itensArray objectAtIndex:i] setString:APROVED forKey:STATE];
            break;
        }
    }

I initialize the array, then later on, i change a string of the NSMutableDictionary. When i set the value i get the following runtime error:

'NSInvalidArgumentException', reason: '-[__NSCFDictionary setString:forKey:]: unrecognized selector sent to instance 0x7b7d170'

It appears i´m not changing the value correctly. Is it a syntax error? How is it done?

Upvotes: 0

Views: 204

Answers (2)

holex
holex

Reputation: 24041

maybe you misspelled the name of the method.

// WRONG
[[itensArray objectAtIndex:i] setString:APROVED forKey:STATE];

// GOOD
[[itensArray objectAtIndex:i] setValue:APROVED forKey:STATE];

Upvotes: 2

CSmith
CSmith

Reputation: 13458

'NSInvalidArgumentException', reason: '-[__NSCFDictionary setString:forKey:]: unrecognized selector sent to instance 0x7b7d170'

NSMutableDictionary has no setString:forKey: method.

Try setObject:forKey:

[[itensArray objectAtIndex:i] setObject:APROVED forKey:STATE]; 

Upvotes: 1

Related Questions