views:

70

answers:

1

I currently add data to a NSMutableArray and then read back from it to populate a UITableview. This works fine on the simulator, but when testing on the device it doesnt work. The app still reads from the plist, so if I manually add data to it the app displays it in the tableview. But Cannot read or write to it on app ?

I use the current code

newTitle = [NSString stringWithFormat:@"%d_%@",[Daily_QuoteViewController counter], t];
[plistArray addObject:newTitle];
[plistArray writeToFile:filepath atomically: YES];

I have read that the list needs to be serialized as well, but others say this isnt necessary?

Any help is appreciated.

Thanks

+3  A: 

Are you sure your app has write permissions to the location you are trying to write the plist to? There are differences between the file system access on the simulator and the actual device.

Update: You can read more about the folders available for your app in iPhone Application Programming Guide: A Few Important Application Directories. The standard way of getting the locations of these folders is described in iPhone Application Programming Guide: Getting Paths to Application Directories. Here's an example how to get the Documents folder and construct a path to a file in it:

NSArray *paths = NSSearchPathForDirectoriesInDomains(
                     NSDocumentDirectory,
                     NSUserDomainMask, YES
                 );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *urla = [NSURL fileURLWithPath:[documentsDirectory
                         stringByAppendingString:@"/myinfo.plist"]];

Which application folder you will use depends on the actual content of your file and the intended use.

Franci Penov
I am sure I don't have. It reads from the plist with the correct filepath. but doesnt add anything to it when app is running. How do I get the permissions? regards
alJaree
You can't get additional permission besides what iOS gives you to begin with.
Franci Penov
Oh, what is the path to write to the documents directory? regards
alJaree
he already gave it to you NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
valexa
@valexa - his comment was before the update to my answer.
Franci Penov
What if the file doesnt exist there? How is it created?
alJaree