Chapter 18 Saving, Loading, and Application State

1. Archiving is one of the most common ways  of persisting model objects on iOS. Archiving an object involves recording all of its properties and saving to the filesystem. Unarchiving recreates the object that from the data.

Classes whose instances need to be archived and unarchived must conform to the NSCoding protocol and implement its two required methods, encodeWithCoder: and initWithCoder:

2.  Below is how archiverRootObject:toFile: works:

The method begins by creating an instance of NSKeyedArchiver. (NSKeyedArchiver is a concrete subclass of the abstract class NSCoder.)

privateItems is sent the message encodeWithCoder: and is passed the instance of NSKeyedArchiver as an argument.

3. In order to have objects that are not view controllers respond to low memory warning, you must use the notification center. Every application has an instance of NSNotificationCenter, which works like a smart bulletin board. An object can register as an observer (“Send me ‘lost dog’ notifications”). When another object posts a notification (“I lost my dog”), the notification center forwards the notification to the registered observers. Whenever a low-memory warning occurs, UIApplicationDidReceiveMemoryWarningNotification is posted to the notification center. Objets that want to implement their own low-memory warning handlers can register for this notification.

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

[notificationCenter addObserver:self

selector:@selector(clearCaches:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];

4. The standard Model-View-Controller design pattern calls for the controller to be bear the burden of saving and loading model objects. However, in practice, this can become overwhelming - the controller is simply too busy handling the interactions between model and view objects to deal with the details of how objects are fetched and saved. Therefore, it is useful to move the logic that deals with where model objects come from and where they are saved to into another type of object: a store.

A store exposes a number of methods that allow a controller object to fetch and save model objects. The details of where these model objects come from or how they get there is led to the store. The store could access a database, talk to a web service, or use some other method to produce the model objects for the controller.

时间: 2024-10-15 20:55:49

Chapter 18 Saving, Loading, and Application State的相关文章

[转]Session and application state in ASP.NET Core

本文转自:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state By Rick Anderson and Steve Smith+ HTTP is a stateless protocol; the Web server treats each HTTP request as an independent request. The server retains no knowledge of variable va

[React] Keep Application State in Sync with Browser History

Using pushState and passing route data via context allows our application to respond to route changes made from Link components, but using the back and forward buttons in the browser doesn’t update the application state as we would expect. In this le

运行iis出现:The server has encountered an error while loading an application ……的解决办法【转】

本人测试了下,第三种方法成功了. 然后经过网上搜索,3种解决方法: 第一种: MC检测到此管理单元发生一个错误.建议关闭并重新启动MMC 要变通解决此问题, 请按照下列步骤操作进入 WMI MMC 管理单元:1. 开始——运行——输入mmc然后单击 确定 . 2. 在 文件 菜单上, 单击 " 添加/删除管理单元 . 3. 在 添加/删除管理 - 中 对话框中, 单击 添加 . 4. 在 可用的独立管理单元 列表, 选择 WMI 控制 , 并单击 确定 . 问题解决! 如果上述不能解决请尝试以下

零元学Expression Blend 4 - Chapter 18 用实例了解互动控制项「CheckBox」II

原文:零元学Expression Blend 4 - Chapter 18 用实例了解互动控制项「CheckBox」II 延续上一章的CheckBox教学,本章将以实作继续延伸更灵活的运用CheckBox. 看Blend如何把CheckBox变成飞碟! ? 延续上一章的CheckBox教学,本章将以实作继续延伸更灵活的运用CheckBox. 看Blend如何把CheckBox变成飞碟! ? ? ? 灵感取自经典动画!「怪兽大战外星人」!!!!!! ? ? ? 本章需要两张图片,一为幽浮.另一个是

[React] Use React Context to Manage Application State Through Routes

We’ll create a Router component that will wrap our application and manage all URL related state. We’ll see how we can use React’s built in context mechanism to pass data and functions between components without having to pass props all the way down t

[Javascript] Manage Application State with Immutable.js

Learn how Immutable.js data structures are different from native iterable Javascript data types and why they provide an excellent foundation on which to build your application's state. Instead of them being mutable, they're always immutable, meaning

[Functional Programming ADT] Initialize Redux Application State Using The State ADT

Not only will we need to give our initial state to a Redux store, we will also need to be able to reset our state at any time by dispatching an action. We can get the best of both worlds by having a function that will return an object with all of our

Head first java chapter 18 远程部署的RMI_分布式计算

iOS UIKit 框架 346 篇文档分类整理 - 预告

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 当前正在进行的是 "iOS Foundation 框架 224 篇相关文档分类整理",量很大,但会根据实际开发中的使用频繁程序