将核心数据添加到XCode 4中的现有项目 [英] Adding Core Data to existing project in XCode 4

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

问题描述

我从没有Core Data的项目开始,现在我想将该功能添加到我的应用程序中。我如何做到这一点?

I started off the project without Core Data and now I would like to add that functionality to my apps. How do I do this?

当您在创建新项目时实际选中使用核心数据时,XCode还会设置什么?

What additional things does XCode sets up when you actually tick the Use Core Data when you create a new project?

推荐答案

一个诀窍是创建一个新的空项目与Core Data支持。这将给你必要的代码,您可以复制到您的原始项目和编译。

One trick is to just create a new empty project with Core Data support. That will give you the necessary code that you can copy over to your original project and compile.

唯一的问题是您需要处理Core Data头文件。 Xcode在使用模板生成文件时将其放在预编译的头文件中。因此,您可以将以下行添加到您的.pch文件:

The only gotcha is that you need to handle the Core Data header file. Xcode puts it in the precompiled header files when it generates files using the templates. So you can add the following line to your .pch file:

#import <CoreData/CoreData.h>

或者您只需将它添加到所需的.m文件。

or you can just add it to the .m files where needed.

它的作用就像一个魅力。注意Luka的下面的评论如何做在Xcode5。

It works like a charm. Notice Luka's comment below about how to do it in Xcode5.

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

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