iOS: store two NSMutableArray in a .plist file

Create an NSArray containing your two NSMutableArrays. NSArray *array = [NSArray arrayWithObjects:<#(id), …#>, nil]; Write the array to a file. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); NSString *libraryDirectory = [paths objectAtIndex:0]; NSString *location = [libraryDirectory stringByAppendingString:@”/somefilename.plist”]; [array writeToFile:location atomically:YES]; Load the array from the file. NSString *path = [bundle pathForResource:@”file” ofType:@”plist”]; NSArry *array = (path … Read more

iPhone read/write .plist file

I guess you have added your plist file to your resources folder in Xcode (where we place image, if not then you need to place that first). Resources data goes to [NSBundle mainBundle] by default and iOS does not allow us to change data inside bundle. So first you need to copy that file to … Read more

How to write a data in plist?

You are trying to write the file to your application bundle, which is not possible. Save the file to the Documents folder instead. NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; path = [path stringByAppendingPathComponent:@”drinks.plist”]; The pathForResource method can only be used for reading the resources that you added to your project in Xcode. Here’s what … Read more

Replace occurrences of NSNull in nested NSDictionary

A small modification to the method can make it recursive: @interface NSDictionary (JRAdditions) – (NSDictionary *) dictionaryByReplacingNullsWithStrings; @end @implementation NSDictionary (JRAdditions) – (NSDictionary *) dictionaryByReplacingNullsWithStrings { const NSMutableDictionary *replaced = [NSMutableDictionary dictionaryWithDictionary: self]; const id nul = [NSNull null]; const NSString *blank = @””; for (NSString *key in self) { const id object = [self … Read more