JSON和核心数据:我应该将JSON转换为核心数据吗? [英] JSON and Core Data:Should I convert JSON into Core Data?

查看:235
本文介绍了JSON和核心数据:我应该将JSON转换为核心数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Core Data的新手,我需要一些项目帮助。

I'm new to Core Data and I need some help on my project.

我正在开发iPhone应用程序,该应用程序从服务器获取JSON(餐馆信息),在地图和表格视图上显示位置,并通过按添加收藏夹按钮来存储收藏的餐厅。

I'm developing iPhone app that get JSON (Restaurants info) from server and shows the location on the map and table view, and stores favorite restaurants by pressing "add favorite" button.

现在,我仅使用NSDictionary及其功能来在表格和注释上显示数据,并具有favoriteRestaurant实体来存储收藏的餐厅数据。

For now, I'm just using NSDictionary and its functions to display data on the table and annotations and having favoriteRestaurant entity to store favorite restaurant data.

但是,我想将NSDictionary对象转换为Core Data对象(Restaurant),并向其添加 BOOL isFavorite属性,然后删除favoriteRestaurant实体。
Make函数,用于保存通过的餐厅对象并更改其 isFavorite状态,该状态由添加收藏夹按钮触发。

However, I would like to convert the NSDictionary object into Core Data object (Restaurant), and add "BOOL isFavorite" attribute to it and then delete favoriteRestaurant entity. Make function that saves the restaurant object that passed and changes its "isFavorite" state, which is triggered by "add Favorite" button.

收藏夹表显示

我想知道这是否是实现我想要的正确方法。
提前谢谢!

I would like to know if this is right approach to accomplish what I want. Thank you in advance!

谢谢您的快速回复。我忘了说我也想对该类实现MKAnnotation,因此地图上的每个注释图钉都属于唯一的餐厅对象。如果要执行此操作,我应该拥有另一个喜欢的类或Core Data实体,还是只将其保存在Restaurant表中,并使isFavorite = YES?再次感谢您!

Hi, thank you for fast responses. I forgot to say that I also want to implement MKAnnotation to that class so each annotation pin on the map belongs to unique restaurant object. If I want to do this, should I have another favorite class or Core Data entity, or just save it in the Restaurant table and make isFavorite = YES? Thank you, again!

推荐答案

我喜欢您的方法。我认为核心数据是必经之路。

I like your approach. In my opinion Core Data is the way to go.

如果您将来会获得很多带有更多数据字段的JSON记录(例如,数十或数百家餐馆),则在使用 NSDictionary s的数组。请记住,序列化的plist只能完全检索,因此,如果plist变大,则必须将所有数据保留在内存中。

If you get lots of JSON records (say, dozens or hundreds of restaurants) with maybe even more data fields in the future, you could run into memory problems when using an array of NSDictionarys. Remember, a serialized plist can only be retrieved entirely, so if it gets large you will have to keep all the data in memory.

此外,您将非常希望拥有一个从一开始就具有更好的性能。

Also, you will very like have a much better performance from the start.

您的 BOOL 属性(在核心数据中为 NSNumber )应该可以正常工作。

Your BOOL attribute (in Core Data that would be a NSNumber) should work fine for your purpose.

这篇关于JSON和核心数据:我应该将JSON转换为核心数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆