目前,我有一个应用程序,用户单击地图并添加带有某些字幕的注释点。然而,当手机重新启动时,所有添加的积分都会消失。我有兴趣使这些注释持久化。我一直在尝试弄清楚如何使用 Core-Data 执行此操作,但在阅读本教程后: http://www.raywenderlich.com/934/core-data-tutorial-getting-started,我有点不知道从哪里开始。
任何帮助将不胜感激,谢谢。
Currently, I have an application where a user clicks on a map and adds annotation points with certain subtitles. However, when the phone is power-cycled, all their added points are gone. I'm interested in making these annotations persistent. I've been trying to figure out how to do this with Core-Data, but after reading this tutorial here: http://www.raywenderlich.com/934/core-data-tutorial-getting-started, I'm a bit lost on where to start.
Any help would be appreciated, thanks.
发布评论
评论(1)
如果您设置了核心数据应用程序,则只需在 xcdatamodel 文件中创建一个实体。为您想要存储的任何内容添加属性。
等等,直到你得到你想要的。
当您想要添加注释时,您应该为您的实体创建一个新的核心数据对象。它看起来像这样,
如果稍后更改值,您可以在不同的点设置属性。您只需要能够访问正确的对象即可使用注释。您应该能够通过使用 NSFetchRequest 在你的 ManagedObjectContext 中。您可以使用 NSPredicate 将对象过滤到您想要的对象。然后,当您准备退出应用程序时,保存您的上下文
,它将存储您添加的所有对象,以便下次打开应用程序时使用。然后,您将能够根据 ManagedObjectContext 中的对象创建注释。我希望这就是您正在寻找的东西,或者至少让您知道如何完成您想做的事情。
If you have a core data application set up, you will only need to create an entity in the xcdatamodel file. Add attributes for whatever you may want to store.
etc. until you have what you want.
When you want to add an annotation, you should create a new core data object for your entity. It will look something like this
You can set the attributes at different point if you change the values at a later point. You just need to be able to access the right object to go with the annotation. You should be able to do this by using NSFetchRequest in your managedObjectContext. You can use NSPredicate to filter the objects to the one you want. Then when you are ready to exit the app, save your context using
which will store all the objects you've added to be used next time you open the app. You will then be able to create your annotations based on the objects in your managedObjectContext. I hope this is what you were looking for, or at least gives you an idea how to approach what you'd like to do.