---
title: "Retreiving string from NSDictionary"  
description: "Retreiving string from NSDictionary"  
author: "Tarun Kumar"  
published: 2015-07-17  
updated: 2015-07-17  
canonical: https://www.mindstick.com/forum/23349/retreiving-string-from-nsdictionary  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Retreiving string from NSDictionary

Im working on the following [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server):

```
-(void)logResults:(NSDictionary *)results {
    NSMutableString *logString = [[NSMutableString alloc]init];
    for (NSString *key in results) {
        if([key isEqualToString:@"index"]){
            NSString *string = [[NSString alloc]initWithString:[results objectForKey:key]];
            string = [string stringByReplacingOccurrencesOfString:@"\n" withString:@""];
            [results setValue:string forKey:key];
        }
        NSLog(@"KEY: %@, VALUE: %@", key, [results objectForKey:key]);
        [logString appendFormat:@"|%@ = %@ \n", key, [results objectForKey:key]];
    }
    self.logInfo.text = [logString stringByAppendingString:self.logInfo.text];
}
```

[problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) lies within the if, I get the following [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing): [_NSArrayM [length](https://www.mindstick.com/interview/1915/what-is-the-difference-between-char_length-and-length)] unrecognised sel...

I was first attempting to use following [expression](https://www.mindstick.com/articles/1861/sqlite-expressions) for the if's work:

```
//[results setValue:[((NSString *)[results objectForKey:key])stringByReplacingOccurrencesOfString:@"\n" withString:@""] forKey:@"index"];
```

which resulted in:

Terminating app due to uncaught [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) 'NSInvalidArgumentException', reason: '-[__NSArrayM stringByReplacingOccurrencesOfString:withString:]

## Replies

### Reply by Anonymous User

Your [results objectForKey:key]];

is returning an array which is causing all of your crashes.

To create a NSString from the array use [results valueForKey:@"description"] componentsJoinedByString:@""];


---

Original Source: https://www.mindstick.com/forum/23349/retreiving-string-from-nsdictionary

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
