<div dir="ltr">A great article on a subject.<div><a href="http://useyourloaf.com/blog/core-data-code-generation/">http://useyourloaf.com/blog/core-data-code-generation/</a><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 17, 2017 at 2:21 AM, Jack Lawrence via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">This is better suited to the Apple developer forums/stack overflow, FYI.<div><br></div><div><span class=""><blockquote type="cite"><div dir="ltr"><div>I selected &quot;Class Definition&quot; in the CodeGen pop up menu in the inspector.</div></div></blockquote></span><div>This tells Xcode to automatically create and maintain the entity classes for you. They don&#39;t show up in the project navigator because they&#39;re autogenerated files, but they&#39;re available via autocomplete and command-click jump to definition.</div><div><br></div><div><span class=""><blockquote type="cite"><div dir="ltr"><div>I then asked Xcode to generate the files with the &quot;Create NSManagedObject subclasses&quot;.</div></div></blockquote></span>Xcode has already generated NSManagedObject subclasses for you, so you&#39;ve now created duplicate classes. That&#39;s why you&#39;re getting this:</div><span class=""><div><br></div><div><blockquote type="cite"><div dir="ltr"><div>But everything breaks. Building the project, I now get several errors similar to this:</div><div><br></div><div><div style="margin:0px 0px 0px 12px;font-size:11px;line-height:normal;font-family:menlo">&lt;unknown&gt;:0: error: filename &quot;PHAudioFile+CoreDataClass.<wbr>swift&quot; used twice: </div></div></div></blockquote><br></div></span><div>TL;DR: Don&#39;t create NSManagedObject subclasses manually—they&#39;re already created and automatically updated for you in Xcode 8.</div><br><div><blockquote type="cite"><div><div class="h5"><div>On Jan 15, 2017, at 10:01 PM, Jean-Denis Muys via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br class="m_-8861200943465125931Apple-interchange-newline"></div></div><div><div><div class="h5"><div dir="ltr">Hi,<div><br></div><div>Using Xcode 8.2.1 I just created a brand new document-based Cocoa application using Core Data and Swift. I created a single entity in the Document.xcdatamodeld file. I selected &quot;Class Definition&quot; in the CodeGen pop up menu in the inspector.</div><div><br></div><div>My entity is named PHAudioFile.</div><div><br></div><div>I then asked Xcode to generate the files with the &quot;Create NSManagedObject subclasses&quot;. It generated two files:</div><div><br></div><div><div>- PHAudioFile+CoreDataClass.<wbr>swift</div></div><div><div>- PHAudioFile+<wbr>CoreDataProperties.swift</div></div><div><br></div><div>But everything breaks. Building the project, I now get several errors similar to this:</div><div><br></div><div><div style="margin:0px 0px 0px 12px;font-size:11px;line-height:normal;font-family:menlo">&lt;unknown&gt;:0: error: filename &quot;PHAudioFile+CoreDataClass.<wbr>swift&quot; used twice: &#39;/Users/jdmuys/Phoenix/<wbr>PHAudioFile+CoreDataClass.<wbr>swift&#39; and &#39;/Users/jdmuys/Library/<wbr>Developer/Xcode/DerivedData/<wbr>Phoenix-<wbr>buxfnwoppzieggdrogkoajdyimri/<wbr>Build/Intermediates/Phoenix.<wbr>build/Debug/Phoenix.build/<wbr>DerivedSources/<wbr>CoreDataGenerated/Document/<wbr>PHAudioFile+CoreDataClass.<wbr>swift&#39;</div><p style="margin:0px 0px 0px 12px;font-size:11px;line-height:normal;font-family:menlo">
</p><div style="margin:0px 0px 0px 12px;font-size:11px;line-height:normal;font-family:menlo">&lt;unknown&gt;:0: note: filenames are used to distinguish private declarations with the same name</div></div><div><br></div><div>More over, the Xcode editor shows many syntax errors in the generated files.</div><div><br></div><div>PHAudioFile+CoreDataClass.<wbr>swift contains this:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">import</span><span style="font-variant-ligatures:no-common-ligatures"> Foundation</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">import</span><span style="font-variant-ligatures:no-common-ligatures"> CoreData</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">@objc</span><span style="font-variant-ligatures:no-common-ligatures">(PHAudioFile)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span><span style="font-variant-ligatures:no-common-ligatures"> PHAudioFile: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">NSManagedObject</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">With this error on the &quot;</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures"> </span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures"> PHAudioFile</span>&quot; line:</div><div><br></div><div>&quot;Invalid redeclaration of <span style="font-family:menlo;font-size:11px">PHAudioFile</span>&quot;</div><div><br></div><div><div>PHAudioFile+<wbr>CoreDataProperties.swift starts with this line:</div></div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">extension</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures">PHAudioFile</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div>Which breaks with:</div><div><br></div><div>&quot;&#39;<span style="font-family:menlo;font-size:11px">PHAudioFile</span>&#39; is ambiguous for type lookup in this context&quot;</div><div><br></div><div>and of course every line thereafter breaks too.</div><div><br></div><div>Searching for &#39;<span style="font-family:menlo;font-size:11px">PHAudioFile</span>&#39; in my Xcode project, finds only those two files. In particular I can&#39;t find any other declaration for &#39;<span style="font-family:menlo;font-size:11px">PHAudioFile</span>&#39;.</div><div><br></div><div>Am I missing something, or is this broken?</div><div><br></div><div>Thanks,</div><div><br></div><div>Jean-Denis</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>has this line in error:<br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div><span class="">
______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></span></div></blockquote></div><br></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>