简体   繁体   English

从核心数据和关系开始

[英]Starting out with Core Data and relationships

What I'm trying to build is an application that allows users to add a category to the first entity (CategoryItem) and then add feeds to that via a second entity (FeedItem). 我要构建的应用程序允许用户向第一个实体(CategoryItem)添加类别,然后通过第二个实体(FeedItem)向其中添加供稿。

So far, the CategoryItem entity has *action attribute which is used as the naming of the category (String). 到目前为止,CategoryItem实体具有* action属性,该属性用作类别(字符串)的命名。 The FeedItem entity has two attributes, *feedName and *feedURL, both strings. FeedItem实体具有两个字符串* feedName和* feedURL。

I have already coded everything to allow the user to create a new category in the first entity, but once that is done and added into the UITableView which is reloaded, I want to allow the user to click the disclosure button which will push a new ViewController that allows the addition of feeds (FeedItem) to the second entity. 我已经对所有内容进行了编码,以允许用户在第一个实体中创建新类别,但是一旦完成并将其添加到重新加载的UITableView中,我想允许用户单击显示按钮,这将推动新的ViewController允许将提要(FeedItem)添加到第二个实体。 Once hitting done, this feed is then added to the appropriate first entity (CategoryItem). 一旦完成,该提要便被添加到适当的第一个实体(CategoryItem)。

My question is how do I link the FeedItem entity to the CategoryItem via a relationship? 我的问题是如何通过关系将FeedItem实体链接到CategoryItem? Then how do I do the above, allowing the user to click the disclosure button of the added CategoryItem push a new ViewController that then allows the addition of the FeedItem. 然后,我该如何做,允许用户单击添加的CategoryItem的显示按钮,推动一个新的ViewController,然后允许添加FeedItem。

This pushed ViewController would need two input boxes and a button (extremely simple to add) that would then write the values to the *feedName and *feedURL attributes. 推送的ViewController将需要两个输入框和一个按钮(极其简单地添加),然后将值写入* feedName和* feedURL属性。

The rest of the application I can do myself, such as parsing the RSS feeds using the TouchXML library. 我可以自己完成应用程序的其余部分,例如使用TouchXML库解析RSS feed。 At the moment I'm just a little stuck on the way we can manipulate Core Data in Objective-C. 目前,我对在Objective-C中操作Core Data的方式只停留了一点。

Any help would be appreciated! 任何帮助,将不胜感激!

[EDIT: If someone could post any tutorials/links that detailed this in depth it would be appreciated. [编辑:如果有人可以发布任何详细介绍了此内容的教程/链接,我们将不胜感激。 However, please don't link to the iOS resource docs, I've already gone through them multiple times now.] 但是,请不要链接到iOS资源文档,我已经多次浏览过它们。]

A possible implementation to get what you need would be: 一种可能的实现方式来满足您的需求:

  1. Add a "To-many" Relationship to the CategoryItem called "feeds"; 向类别项添加“一对多”关系,称为“提要”;
  2. Add a Relationship to the FeedItem called "category"; 在FeedItem中添加一个名为“ category”的关系;
  3. Set the inverse relationship of "feeds" to "category" (or vice-versa); 将“提要”的反比关系设置为“类别”(反之亦然);
  4. Instantiate a new FeedItem managed object every time you push a new "Add FeedItem" ViewController; 每当您按下新的“ Add FeedItem” ViewController时,实例化一个新的FeedItem管理对象;
  5. Save the managed object context after pressing "Done". 按“完成”后,保存托管对象的上下文。

If you've already read all the resource documents, you could study the sample code, especially "Locations" and "CoreDataBooks". 如果您已经阅读了所有资源文档,则可以研究示例代码,尤其是“ Locations”和“ CoreDataBooks”。 Hope this helps. 希望这可以帮助。

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

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