0

I have an NSArray of NSStrings that I am saving to file and then reloading from file when the app is relaunched. Strangely though, the strings have parenthesis around them after they are reloaded.

I save via: writeToFile:atomically:

and I load the array via: arrayWithContentsOfFile:

The issue is that when the NSString goes in it might look like this:

I_am_the_good_old_string

but after reloading the array from file, it looks like this:

(

I_am_the_good_old_string

)

I don't understand why they now have the parenthesis around them. Any help is appreciated.

daveMac
  • 3,041
  • 3
  • 34
  • 59

2 Answers2

2

I guess the second object you're printing is a NSArray containing one string, not a NSString object itself. Try calling this method to see the name of the object's class.

NSLog(@"%@",[possibleStringObject class]);
ToMfromTO
  • 325
  • 1
  • 4
  • So you are right, it turns out that it is an array. That's weird to me that when you save an array populated with NSString's that they get saved out as individual arrays...each containing one string. Any idea why this is? – daveMac Feb 04 '13 at 19:48
  • My mistake, it turns out that where I thought I was adding an NSString, I was accidentally adding an NSArray that contained a string. Thanks for the help though. – daveMac Feb 04 '13 at 20:54
1

The parenthesis is an array object, if you print out an array, it calls [myarray description] which looks like what you described..

(obj1,
obj2,
obj3)

You're probably printing the string, then printing the array. Try printing the string after reloading the array..

NSLog(@"myString:%@", [myArray objectAtIndex:0]);
estobbart
  • 1,137
  • 12
  • 28