简体   繁体   English

现在xcode 4改变了生成的代码,我应该如何将项目添加到Core Data中的列表?

[英]How should I add items to a list in Core Data now that xcode 4 changed the generated code?

I have a core data model with a parent item and child items under it. 我有一个核心数据模型,其中包含父项和子项。 In Xcode 3, when I generated the NSManagedObjects for this, I had methods called addChildsObject object method on Parent, but this has gone away in Xcode 4 (see Xcode4: Different code generated for custom core data managed objects ). 在Xcode 3中,当我为此生成NSManagedObjects时,我在Parent上有一些名为addChildsObject对象方法的方法,但是在Xcode 4中已经消失了(参见Xcode4:为自定义核心数据管理对象生成的不同代码 )。 My question is this: how should I be adding the children to the parent now? 我的问题是:我现在应该如何将孩子加入父母? I really don't want to mess with the generated code, revert to using Xcode3, or add a category to Parent to bring back the missing methods. 我真的不想搞乱生成的代码,恢复使用Xcode3,或者向Parent添加一个类别来恢复缺少的方法。 Is there an approved way, or did Apple just muck up the whole process? 是否有批准的方式,或苹果只是搞砸了整个过程?

After discovering and reviewing the documentation on Dynamically-Generated Accessor Methods , it appears that Apple still recommends using the now non-existent methods, so it would appear that they have just screwed up by removing them. 在发现并查看有关动态生成的访问器方法文档之后,Apple似乎仍然建议使用现在不存在的方法,因此看起来他们刚刚通过删除它们而搞砸了。 There is, however, another recommended way of doing this: 但是,还有另一种推荐的方法:

NSMutableSet *children = [parent mutableSetValueForKey:@"child"];
[children addObject: child1];
[children removeObject: child2];

This is not fabulous, because it relies on an unchecked string name, but it's the only remaining recommended way to do this without custom implementations. 这并不是很棒,因为它依赖于未经检查的字符串名称,但它是唯一一种在没有自定义实现的情况下执行此操作的方法。 Thanks a lot Apple! 非常感谢Apple!

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

相关问题 Xcode4:为自定义核心数据管理对象生成不同的代码 - Xcode4: Different code generated for custom core data managed objects xCode生成的核心数据堆栈代码逻辑和核心数据样本代码存在问题 - Issue with xCode generated core data stack code logic and core data sample code 我可以向Core Data生成的类添加自定义方法吗? - Can I add a custom method to Core Data-generated classes? 我应该如何迁移核心数据? - How should I migrate my core data? 我应该多久保存一次Core Data? - How often should I save to Core Data? 我应该如何防御性地编写可能的核心数据文件损坏或加载问题? - how should I defensively code for possible core data file corruption or loading issues? 我应该使用Core Data作为IOS自动完成列表的数据源吗? - Should I use Core Data as a datasource for an IOS Autocompletion List? 如何在我的Xcode项目中添加Core Animation框架? - How can I add Core Animation framework to my Xcode project? Xcode 3.2.1 - 为什么生成核心数据的类会导致构建错误? - Xcode 3.2.1 - Why are Core Data generated Classes resulting in Build errors? 我更改了项目所在文件夹的名称,现在Xcode找不到我的项目 - I Changed The Name Of The Folder My Project Was In And Now Xcode Cannot Find My Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM