0

So I'm working on an iOS app which uses Core Data as a local, offline store for data stored on a remote server. Think like the way Mail.app keeps your most recent n messages. Now right now the app quite naively stores all of this data without deleting any of the old data.

My question is this: what's the best time in an iOS app's lifecycle to take care of tasks like removing cached data? I already know how I'm going to delete this old data, but doing so is an expensive operation. So what I want to know is when the best time to perform this sort of expensive operation is.

4

2 回答 2

1

如果不是太麻烦,那么当应用程序进入后台时这样做将是一个很好的时机。但是,如果需要大约 10 秒或更长时间,请务必设置后台任务以允许您运行更多时间。

于 2013-06-26T03:47:33.897 回答
0

您可以使用 GCD 或 NSOperationQueue 在后台运行此操作。我会在从服务器获取新数据后执行此操作,然后删除旧缓存并构建新缓存。如果您将昂贵的操作移到后台(线程、块、NSOperation 或您喜欢的任何东西),那么最好使用子 NSMagaedObjects 进行同步。

于 2013-06-28T11:30:51.803 回答