简体   繁体   English

将核心数据添加到现有的iPhone应用程序

[英]Adding Core Data to an existing iPhone app

I have started my application and now I want to add Core Data to my app. 我已经启动了我的应用程序,现在我想将Core Data添加到我的应用程序中。 How can I add it? 我该如何添加它?

I disagree that you have to start a new project. 我不同意你必须开始一个新项目。 It's actually pretty easy to integrate CoreData into an existing project - a good starting point is to create a new CoreData project, but copy the code it generates into your existing project (examine carefully the app delegate to see what it sets up). 将CoreData集成到现有项目中实际上非常容易 - 一个很好的起点是创建一个新的CoreData项目,但将它生成的代码复制到现有项目中(仔细检查应用程序委托以查看它设置的内容)。 There's really not that much code involved, and it's easy to create new data models. 实际上没有那么多代码涉及,并且很容易创建新的数据模型。

It's also a really good idea to work through Apple's CoreData tutorials to understand what is going on, and there are some good books as well. 通过Apple的CoreData教程来理解正在发生的事情也是一个非常好的主意,并且还有一些好书。

Unless you've gotten really far into your app, the easiest way will be for you to start a new Xcode project using the Core Data template. 除非您已经深入了解应用程序,否则最简单的方法是使用Core Data模板启动新的Xcode项目。 If you really don't want to move your code into a new project, you can add the Core Data framework and the necessary boilerplate code in AppDelegate. 如果您真的不想将代码移动到新项目中,可以在AppDelegate中添加Core Data框架和必要的样板代码。 But really, unless you want to be tinkering for a while, the simplest way is to make a new project with the right template. 但实际上,除非你想要修补一段时间,最简单的方法是使用正确的模板制作一个新项目。

How much code do you have written? 你写了多少代码? It may be simplest to start a new project with the Core Data template, and migrate in your existing code. 使用Core Data模板启动新项目并在现有代码中迁移可能最简单。

Not sure how much experience you have with Core Data, but the default template adds a bit of bloat in my opinion. 不确定你对Core Data有多少经验,但默认模板在我看来增加了一些膨胀。 Be prepared to alter it to suit your needs. 准备改变它以满足您的需求。

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

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