You are trying to write the main bundle which is no-no on iOS. Please read the A Few Important Application Directories But your coding boils down to the following: Check if plist is not in Application_Home/Documents Copied original plist from main bundle is the answer to step 1 is false Open the plist in the Documents directory Update NSMutableArray Write to file the plist.
You are trying to write the main bundle which is no-no on iOS. Please read the A Few Important Application Directories. But your coding boils down to the following: Check if plist is not in Application_Home/Documents/ Copied original plist from main bundle is the answer to step 1 is false.
Open the plist in the Documents directory Update NSMutableArray Write to file the plist.
Please refer to my updates, I still cannot get it work, thanks ~ – Michael Sep 28 at 13:18 The code in your question is still point the file in the main bundle. You didn't do step 2 in my answer which is to copy the plist from the main bundle to the documents folder. – Black Frog Sep 28 at 14:18 Yes, this is where I don't understand, I thought if loop does the copy, can you show me some code of how to copy from bundle to local and backwards?
– Michael Sep 28 at 16:43 There is plenty of code sample out there on this matter. For example: iPhone (iOS): copying files from main bundle to documents folder error – Black Frog Sep 28 at 20:25.
I think code is not wrong. Have you check plistPath, dataRoot, and item? They have correct value?
– Michael Sep 28 at 5:47 @Michael If you read file as nsmutablearray. Multi levels plist is not cosiderable thing. Program add object to nsmutablearray.
– ChangUZ Sep 28 at 6:09 @Michael and How to get plistPath is not good method. Use NSSearchPathForDirectoriesInDomains function. – ChangUZ Sep 28 at 6:11.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = paths objectAtIndex:0; NSString *filePath = documentsDirectory stringByAppendingPathComponent:@"list. Plist"; if (NSFileManager defaultManager fileExistsAtPath:filePath) { bingoArray = NSMutableArray alloc initWithContentsOfFile:filePath; } bingoArray writeToFile:filePath atomically:YES.
You can only save primitive types by default. Try out this link. deadpanic.com/howtosave He explains how to save any object to disk by using NSCoding protocol.
If you are working only with primitives then I apologize for wasting your time. But this is the path I took to write my custom stuff to disk. And I thought it was just an array issue.
Edit: I just noticed... It looks like you are trying to write to an array in the Main Bundle. These files are read only. You need to save a copy of the file in the Documents directory.
Try this out to find the documents directory NSFileManager *fileManager = NSFileManager defaultManager; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = paths objectAtIndex:0; // Change your plistPath to be this plistPath = documentsDirectory stringByAppendingPathComponent:@"list. Plist"; dataRoot writeToFile:plistPath atomically:YES; put your plist in this folder and you can write to it.
– Michael Sep 28 at 5:44 I corrected the spelling error. Volure meant to type NSDocumentDirectory. – Black Frog Sep 28 at 5:56 Now I just added these three lines before the code above, but I don't know how to do the rest, can you show me some example?
– Michael Sep 28 at 6:18.
But this is the path I took to write my custom stuff to disk. And I thought it was just an array issue. I just noticed... It looks like you are trying to write to an array in the Main Bundle.
These files are read only. You need to save a copy of the file in the Documents directory. Put your plist in this folder and you can write to it.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.