How to store NSMutableArray of user defined class objects to file system in iphone?

Posted by chaitanya on Stack Overflow See other posts from Stack Overflow or by chaitanya
Published on 2010-06-12T09:00:05Z Indexed on 2010/06/12 9:13 UTC
Read the original article Hit count: 217

Filed under:
|
|

Can anyone please tell me how to write NSMutableArray of custom class objects to file? below is the code which i am using to write my array "medicationsArray" to file. medicationsArray contains the objects of below medicationData class

@interface medicationData: NSObject { NSString *drName; NSString *date; NSString *description; } @end

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentDir = [path objectAtIndex:0];
NSString *pathWithFileName;

NSString *pathWithFileName = [NSString stringWithFormat:@"%@/medicationsArray",documentDir];
[medicationsArray writeToFile:pathWithFileName atomically:NO];

by using this code i am not able to create a file. can anyone help me in this, thanks in advance

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk