简体   繁体   English

使用Core Data时需要本地数组吗?

[英]Do I need a local array when using Core Data?

I'm currently writing my first iOS app and I'm trying to implement Core Data. 我目前正在编写我的第一个iOS应用,并且正在尝试实现Core Data。 Users create food recipes and I want them saved to persistent storage. 用户创建食物食谱,我希望将它们保存到永久性存储中。

Currently, without Core Data, I'm putting the recipes into an array from a singleton. 目前,在没有Core Data的情况下,我正在将配方从单例放入数组中。

When I implement Core Data can I do away with this and fetch straight from the data model every time I need to update my UITableView ? 当我实现Core Data时,我可以取消它并在每次需要更新UITableView时直接从数据模型中获取吗? In the viewDidLoad method, create an array from the current data in Core Data every time a user navigates to it? viewDidLoad方法中,每当用户导航到它时,便从Core Data中的当前数据创建一个数组?

Yes you can. 是的你可以。

You should look at the class NSFetchedResultsController it is designed to do this. 您应该查看旨在实现此目的的类NSFetchedResultsController

There is a great Ray Wenderlich tutorial which covers everything including things like automatically updating the table when the core data model changes etc... Ray Wenderlich有一个很棒的教程 ,涵盖了所有内容,包括诸如在核心数据模型更改时自动更新表等内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM