aahrens
aahrens

Reputation: 5590

Saving an NSMutableArray of custom Objects

I have a custom class that is used as a wrapper to an NSMutableArray

@interface AllCourses : NSObject {

 NSMutableArray *arrClasses;
}

The array above stores Objects of another custom class.

@interface Course : NSObject {

NSString *className;
NSString *classGrade;
NSInteger creditHours;
}

I use the method below to add Course objects to my AllCourses

//Adds a new Course to the total Courses
-(void) addClass:(Course *)aCourse{
  [arrClasses addObject:aCourse];
 }

What's going to be the best way to save the arrClasses MutableArray in AllCourses so that when my app loads it can keep the saved data the user already entered and populate it?

Upvotes: 1

Views: 994

Answers (1)

kovpas
kovpas

Reputation: 9593

I want to save before the app closes and I want to load the content when the app is started

The easiest way, I think, is to use -[NSArray writeToFile: automatically:] and -[NSArray initWithContentsOfFile:]

Upvotes: 1

Related Questions