核心数据Codegen在Xcode 8中失败 [英] Core Data Codegen fail in Xcode 8

查看:59
本文介绍了核心数据Codegen在Xcode 8中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用,其中包含具有6个实体的Core Data模型.实体Name设置如下:

I have an iOS app containing a Core Data model with 6 entities. The entity Name is set up as follows:

课程名称:名称

模块:当前产品模块

可待因:类定义

(所有其他5个实体的设置都类似).

(all 5 other entities are set up similarly).

问题1 (已修正,但留给后代)

Problem 1 (fixed itself but leaving for posterity)

代码是在派生数据文件夹中生成的……不是按预期的〜类定义,而是扩展名(如Name+CoreDataProperties.swift这样命名.将Codegen设置为Class Definition还是Category/Extension似乎无关紧要-我仍然得到相同的结果.

Code IS generated in the derived data folder… not as ~class definitions as expected, but as extensions instead (named like Name+CoreDataProperties.swift. It doesn't seem to matter whether the Codegen is set to Class Definition or Category/Extension - I still get the same result.

好吧,请保持这种想法-现在突然生成了类文件和扩展文件……看起来您需要删除项目的派生数据文件夹,并在两次更新之间重新启动Xcode.忽略问题1

问题2

生成的文件将忽略字符串属性和关系的数据模型可选标记设置-它们都将作为可选对象生成

Generated files ignore the data model Optional flag setting for String attributes and relationships - they are all generated as optionals

问题3 (已修复,但留给后代)

Problem 3 (fixed itself but leaving for posterity)

有序关系生成为OrderedSet(和编译错误),而不是NSOrderedSet(无法重新生成,因为它们会重新生成)

Ordered relationships are generated as OrderedSet (and a compilation error) rather than NSOrderedSet (can't change them as they get re-generated)

对我来说,解决方法是暂时添加到项目中... public typealias OrderedSet = NSOrderedSet

Workaround for me was to temporarily add to the project… public typealias OrderedSet = NSOrderedSet

好,现在编译器错误消失了,并且似乎已识别出OrderedSet.忽略问题3.

OK, now the compiler error has gone, and OrderedSet seems to be recognised. Ignore Problem 3.

问题4

以上所有内容都不重要,因为编译器找不到刚生成的文件.对于上面的Name实体:

None of the above really matters, because the compiler can't find the files it's just generated. For the Name entity above:

:0:错误:没有这样的文件或目录: '/Users/ashleymills/Library/Developer/Xcode/DerivedData/-grfqveelvqtlydbpwjmfdietnrss/Build/Intermediates/.build/Debug-iphonesimulator/.build/DerivedSources/CoreDataGenerated//..Name+CoreDataClass.swift' :0:错误:没有这样的文件或目录: '/Users/ashleymills/Library/Developer/Xcode/DerivedData/-grfqveelvqtlydbpwjmfdietnrss/Build/Intermediates/.build/Debug-iphonesimulator/.build/DerivedSources/CoreDataGenerated//.. Name + CoreDataProperties.swift'

:0: error: no such file or directory: '/Users/ashleymills/Library/Developer/Xcode/DerivedData/-grfqveelvqtlydbpwjmfdietnrss/Build/Intermediates/.build/Debug-iphonesimulator/.build/DerivedSources/CoreDataGenerated//.Name+CoreDataClass.swift' :0: error: no such file or directory: '/Users/ashleymills/Library/Developer/Xcode/DerivedData/-grfqveelvqtlydbpwjmfdietnrss/Build/Intermediates/.build/Debug-iphonesimulator/.build/DerivedSources/CoreDataGenerated//.Name+CoreDataProperties.swift'

它正在寻找文件.Name+CoreDataClass.swift.Name+CoreDataProperties.swift的派生数据-请注意'.'.在文件名的最前面. (作为临时修复程序,我将生成的文件添加到项目中)

It's looking in derived data for files .Name+CoreDataClass.swift and .Name+CoreDataProperties.swift - notice the '.' at the front of the file names. (As a temp fix I added the generated files into the project)

我认为我做错了,好像每个人都是这样,没有人能够构建Core Data项目……还是这些错误需要提出?

I assume I'm doing something wrong, as if this was the case for everyone, no-one would be able to build a Core Data project… or are these bugs that need raising?

欢呼 灰

(也在Apple开发者论坛上提出)

(Also raised on Apple dev forums)

推荐答案

关于问题1 ,在Inspector中为.xcdatamodel中的实体设置 Codegen 弹出窗口是应该像这样工作:

Regarding Problem 1, setting the Codegen popup in the Inspector for an entity in an .xcdatamodel is supposed to work like this:

类别/扩展名告诉Xcode生成一个文件,即ClassName + CoreDataGeneratedProperties.

Category/Extension tells Xcode to generate one file, ClassName+CoreDataGeneratedProperties.

类定义告诉Xcode生成两个文件,即上述文件,以及ClassName + CoreDataClass.

Class Definition tells Xcode to generate two files, the above-named file, plus ClassName+CoreDataClass.

但是,在Xcode 8.2中似乎存在一个错误.如果在更改了这些弹出窗口之一之后,仅生成(B)或运行(⌘R),则所做的更改将不会生效.例如,如果您从类定义更改为类别/扩展名,甚至手动删除了第二个文件,它将重新出现.您甚至可能会发现弹出窗口恢复为原始设置.

However, there appears to be a bug, in Xcode 8.2. If, after changing one of these popups, you simply Build (⌘B) or Run (⌘R), your changes will not take effect. For example, if you changed from Class Definition to Category/Extension and even manually deleted the second file, it will reappear. You may even find that the popup reverts back to the original setting.

为了使这些弹出窗口中的更改生效,您必须

In order for changes in these popups to become effective, you must

  1. 保存(⌘S).xcdatamodel文件.
  2. 关闭所有项目窗口.
  3. 重新打开项目.
  1. Save (⌘S) the .xcdatamodel file.
  2. Close all project windows.
  3. Re-open the project.

在下一个构建期间(如果故事板中有@IBInspectable,则在打开项目时可能会自动发生),将生成或删除派生数据"中受影响的文件,以符合您的新设置.

During the next build (which may occur automaticallly when the project opens if you have an @IBInspectable in a storyboard), the affected files in Derived Data will be generated or deleted to conform to your new setting.

更新2016-12-22:谢谢你的评论,阿什利.我现在已经写好并将其提交给Apple Bug Reporter:29789727.更新2017-02-08: Apple已经关闭了29789727,因为它可能重复了21205277.

UPDATE 2016-12-22: Thank you for the comment, Ashley. I've now written up and submitted this to Apple Bug Reporter: 29789727. Update 2017-02-08: Apple has closed 29789727 as it supposedly duplicates 21205277.

这篇关于核心数据Codegen在Xcode 8中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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