The internal status of the object is captured and embodied in the memorandum mode. In other words, it can save your things. Later, this external State can be restored without violating encapsulation; that is, private data is private. How to add the following method to the Viewcontroller implementation file using the memorandum design mode:-(void) saveCurrentState {// When the user leaves the app and then comes back again, he wants it to be in the exact same state // he left it. in order to do this we need to save the currently displayed album. // Since it's only one piece of information we can use NSUserDefaults. [[NSUserDefaults standardUserDefaults] setInteger: currentAlbumIndex forKey: @ "cu RrentAlbumIndex "];}-(void) loadpreviusstate {currentAlbumIndex = [[NSUserDefaults standardUserDefaults] integerForKey: @" currentAlbumIndex "]; [self failed: currentAlbumIndex];} saveCurrentState stores the index of the current album with NSUserDefaults, which is a standard storage application setting and data provided by Apple. Loadpreviusstate: load the previously saved index. This is not the full implementation of the memorandum design model. Now add the code before the sliding view initialization: [self loadpreviusstate]; when the application starts, load the previously saved state, but you only save the current turntable of the application to load? You will use notifications to do this. When the application enters the background system, it sends the UIApplicationDidEnterBackgroundNotification. You can use this notification to call saveCurrentState. Isn't that very important? Add the following code to ViewDidLoad: [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (saveCurrentState) name: UIApplicationDidEnterBackgroundNotification object: nil]; now this application enters the background. The saveCurrentState method will be called automatically to save the current state. Now add the following code:-(void) dealloc {[[nsicationcenter center defacenter center] removeObserver: self];} This ensures that the observer registered for this class is removed when Viewcontroller is destroyed. Build and run your application. Navigate to an album and send the application to the background using the command + Shift + H (if you are in the simulator), then close the application, restart, and check before, select albums as the center: It seems that your album data is correct. But your slide view is not in the middle. Why? This is the meaning of the preceding Optional Protocol method initialViewIndexForHorizontalScroller: Because this method is not implemented in the proxy class. In this example, the proxy class is Viewcontroller, so the initial view is always set as the first view. To correct this, he added the following code to the Viewcontroller implementation file:-(NSInteger) initialViewIndexForHorizontalScroller :( HorizontalScroller *) scroller {return currentAlbumIndex ;} now the first view of this slide view can be set to any album as indicated by currentAlbumIndex. This is a good way to ensure that your application experience is private and recoverable. If you look at the init of PersistencyManager, you will notice that the album data is hardware encoded and will be re-created when PersistencyManager is created. The best solution is to store the album list to a file once it is created. So how can I store an album to a file? One way is to iterate the attributes of an album, save them to a plist file, and then create an album instance as needed. However, this is not the best choice, because you need to write specific code based on the attributes and data of each class. For example, the movies class you create next has different attributes, and new code is required to save and load data. In addition, you cannot save the private variables of each class instance because they cannot access the external class. This is why Apple has created an archive mechanism. Archive one of Apple's dedicated memory modes is archive. Converts an object to a stream for saving and restoration without exposing private attributes to external classes. You can refer to the Apple's Archives and Serializations Programming Guide. How to Use archive? First, you need to declare that the album can be archived through the NSCoding protocol. Write in the Album header file that complies with the NSCoding Protocol: @ interface Album: NSObject <NSCoding>. In the implementation file, add two methods:-(void) encodeWithCoder :( NSCoder *) ACO {[ACO encodeObject: self. year forKey: @ "year"]; [aCoder encodeObject: self. title forKey: @ "album"]; [aCoder encodeObject: self. artist forKey: @ "artist"]; [aCoder encodeObject: self. coverUrl forKey: @ "cover_url"]; [aCoder encodeObject: self. genre forKey: @ "genre"];}-(id) initWithCoder: (NSCoder *) aDecoder {self = [super init]; if (self) {_ year = [aDecoder decodeObjectForKey: @ "year"]; _ title = [aDecoder decodeObjectForKey: @ "album"]; _ artist = [aDecoder decodeObjectForKey: @ "artist"]; _ coverUrl = [aDecoder decodeObjectForKey: @ "cover_url"]; _ genre = [aDecoder decodeObjectForKey: @ "genre"];} return self;} You call encodeWithCoder: When you archive an instance of your class, on the contrary, you can archive an instance to create an album instance. It looks simple and powerful. Now the album category can be archived. The added code actually saves and loads the album list. Add the following signature (or method prototype) PersistencyManager. h: This will be called the method to save the album. Now, add PersistencyManager. m method implementation:-(void) saveAlbums {NSString * filename = [NSHomeDirectory () stringByAppendingString: @ "/Documents/albums. bin "]; NSData * data = [NSKeyedArchiver archivedDataWithRootObject: albums]; [data writeToFile: filename atomically: YES];} The Name Of The NSKeyedArchiver array is albums. bin file. When your archive object contains other objects, the archive object automatically iterates the archive sub-objects and any sub-objects of the child. In this case, archive the album category, which is an array of the album instance. Therefore, arrays and albums support the NSCoding interface. Everything in the array will be archived. Now in PersistencyManager. add the following code to the m init method:-(id) init {self = [super init]; if (self) {NSData * data = [NSData dataWithContentsOfFile: [NSHomeDirectory () stringByAppendingString: @ "/Documents/albums. bin "]; albums = [Export unarchiveObjectWithData: data]; if (albums = nil) {albums = [NSMutableArray arrayWithArray: @ [[Album alloc] initWithTitle: @ "Best of Bowie" artist: @ "David Bowie" coverU Rl: @ "http://www.coversproject.com/static/thumbs/album/album_david%20bowie_best%20of%20bowie.png" year: @ "1992"], [[Album alloc] initWithTitle: @ "It's My Life" artist: @ "No Doubt" coverUrl: @ "http://www.coversproject.com/static/thumbs/album/album_no%20doubt_its%20my%20life%20%20bathwater.png" year: @ "2003"], [[Album alloc] initWithTitle: @ "Nothing Like The Sun" artist: @ "Sting" coverUrl: @ "http://www.cover Week "year: @" 1999 "], [[Album alloc] initWithTitle: @" Staring at the Sun "artist: @" U2 "coverUrl: @" http://www.coversproject.com/static/thumbs/album/album_u2_staring%20at%20the%20sun.png "year: @ "2000"], [[Album alloc] initWithTitle: @ "American Pie" artist: @ "Madonna" coverUrl: @ "http://www.coversproject.com/static/thumbs/album/album_m Adonna_american%20pie.png "year: @" 2000 "]; [self saveAlbums] ;}} return self ;}in the new code, NSKeyedUnarchiver loads new album data from the file, if it exists. If it does not exist, immediately create the album data and save it to load the application next time. You also want to save this album every time the application enters the background data. This may not be necessary, but if you add a later option to change the album data, you want to ensure that you have saved all the changes. Add the following LibraryAPI. h method Signature:-(void) saveAlbums; the application accesses all services through libraryAPI. This is how the application makes PersitencyManager know that he wants to save the data of the album. Now add this method to the libraryAPI implementation file:-(void) saveAlbums {[persistencyManager saveAlbums];} This Code only saves the album to PersistencyMangaer by calling LibraryAPI. And the above Code uses LibraryAPI to trigger the Save album data every time Viewcontroller saves its status. Compile and run your application to check whether everything is running normally. Unfortunately, there is no simple way to check data persistence. Fortunately, you can check the document folder of the simulator in the finder to see if the data file of the album is created, but to check whether there is any change, you have to add the function of changing the album data. But instead of changing the data, if you add an option to delete your album when you don't want it. In addition, you should have an undo option once you accidentally delete the album.