核心数据对现有项目iPhone的影响 [英] impact of core data on existing project iphone

查看:50
本文介绍了核心数据对现有项目iPhone的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始研究Core Data,因为许多人声称这是保存数据的最佳方法.

I am starting to have a look at Core Data, as many claiming is the best way to persist data.

我有一个已经在使用其模型和对象的项目,该应用程序的主要目的是将事物作为属性(NString,NSObject,Custom Object..ecc)封装到一个主类中,从而能够创建许多实例此类,然后将其保存到存储中,以后检索并显示包含所有已保存实例的表列表.

I have an already working project with its model and objects, the main purpose of the application is to encapsulate things as attributes (NString,NSObject, Custom Object..ecc) into one main class, give the ability to create many instance of this class then save it to storage, later retrieve and display a table list with all saved instance.

在这种情况下,已经定义了我的类(作为NSObject扩展),那么引入Core Data会发生什么?我需要重写我的模型吗?

In this case, where my class is already defined (as NSObject extension), what could happen with the introduction of Core Data ? Do I need to rewrite my model ?

例如,首先尝试用xcode创建一个模型,然后将我的对象作为实体关联到它.但是某些不使用标准的属性,例如字符串,整数... ecc的类型为UNDEFINED.

For example as a first try I created a model in xcode, then associate my object as entity to it. But some of the attributes that were not using standard such as string, int ...ecc got UNDEFINED as type.

@interface Car {
NSString *name;
WheelsType wtype; <-- undefined
NSDate *buy;
CarColor *color; <-- undefined
}
@end

那是什么意思?我只能保存String,Int,Boolean ... ecc而不保存我的Custom Classes吗?如果不是,那么表结构可能是什么?

What does that mean ? Am I able to save just only String,Int,Boolean...ecc but not my Custom Classes ? If not, what the table structure could be ?

谢谢

推荐答案

CoreData中的自定义类型可以声明为

Custom types in CoreData can be declared transformable, meaning that they'll be transformed to and from instances of NSData. The default value transformer works in many cases, but your classes may require a custom NSValueTransformer.

修改:由于使用 CoreData 会更改您检索数据的方式,因此明智的做法是检查模型.阅读 CoreData 文档,然后考虑如何访问您的对象以及如何避免对将不使用的对象和属性进行故障处理.

Since utilizing CoreData changes how you retrieve your data, it'd be wise to review your model. Read the CoreData documentation and then consider how your objects are accessed and how you can avoid faulting objects and properties that will go unused.

这篇关于核心数据对现有项目iPhone的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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