-1

sorry guys but i cant get the hang of this array lark. Ive tried everthing to make this work before posting yet another question about arrays. But i cant help it im really stuck

here goes

im simply trying to access a value of a key/value pair :

   NSDictionary *itemsInSection  = [self.patternImagesArray objectAtIndex:indexPath.section];
    NSString *groupTitle = [[[itemsInSection allValues] objectAtIndex:1] objectForKey:@"RequestTitle"];

however when attempting to access the groupTitle it crashes with an invalid pointer "RequestTitle" . Which i can assure you is there.

itemsInSection  __NSCFDictionary *  2 key/value pairs   0x00000001555dc410
[0] struct __lldb_autogen_nspair        
[1] struct __lldb_autogen_nspair        
key __NSCFString *  @"RequestTitle" 0x00000001555be430
value   __NSCFString *  @"Council bill" 0x00000001555db260

The result is fixed and the specific key/value will always appear at position 1 in the dictionary.

I have also tried numerous variations of this line:

NSString *groupTitle = [[[itemsInSection allValues] objectAtIndex:1] objectForKey:@"RequestTitle"];

and

NSString *groupTitle = [[[itemsInSection allValues] objectAtIndex:1] valueForKey:@"RequestTitle"];

and

NSString *groupTitle = [[itemsInSection][1] objectForKey:@"RequestTitle"];

to name just a few.

PowerMan2015
  • 1,307
  • 5
  • 19
  • 40
  • Possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](https://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Cœur Jul 08 '19 at 05:55

1 Answers1

1

An NSDictionary is an association of key/value pairs: a given key within the dictionary is unique.

Your NSDictionary (from your output) contains a key called "RequestTitle". If you want to retrieve the value associated with that key, try:

NSString *groupTitle = [itemsInSection objectForKey:@"RequestTitle"];
oroboto
  • 226
  • 1
  • 2