forum

Home / DeveloperSection / Forums / Retreiving string from NSDictionary

Retreiving string from NSDictionary

Tarun Kumar179817-Jul-2015

Im working on the following function:

-(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 lies within the if, I get the following error: [_NSArrayM length] unrecognised sel...

I was first attempting to use following expression 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 'NSInvalidArgumentException', reason: '-[__NSArrayM stringByReplacingOccurrencesOfString:withString:]

 


Updated on 17-Jul-2015

Can you answer this question?


Answer

1 Answers

Liked By