I'm looping through the results of a fetch request against a Core Data store. For each object in the result list, I am reading several attributes of type string and concatenating them into one string (to be output as a CSV format file).
One particular string of one particular record in my dataset is giving me trouble: extraneous characters (kanji, arabic, etc.) are appended to the end of the string, it does not append properly to my result string, and my CSV file format is hosed.
Here is my code for looping through the fetch results and appending the string:
NSMutableString *reportString = [[NSMutableString stringWithFormat:@"...\n"]; for (int s = 0; s < [frc.sections count]; s++) { for (int r = 0; r < [[frc.sections objectAtIndex:s] numberOfObjects]; r++) { NSIndexPath *i = [NSIndexPath indexPathForRow:r inSection:s]; Thread *thread = [frc objectAtIndexPath:i]; NSMutableString *activity = [NSMutableString stringWithString:[thread activity]]; . . . [reportString appendString:activity]; [reportString appendFormat:@",%@\n", client]; } }
I'm using stringWithString here, but I've also used several other string methods with similar, corrupted, results. One time, Arabic letters appeared. Another time, it was "...random...FSO_CARRIER_ATT@2X.png". I've also tried using a separate fetch results array (instead of a fetched results controller).
One weird thing is that when I do a PO from lldb, the string shows up correctly. This may explain why this "corruption" doesn't show up on my table views, just when I am trying to mash strings together.
My Question
Am I copying the string values from the Core Data model incorrectly and causing this to happen? Is there a technique I am missing out on?
Update:
A screenshot of the watched variable versus an NSLog of the value: