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:]
Anonymous User
17-Jul-2015Your [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:@""];