<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"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></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 "Class Definition" 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't show up in the project navigator because they're autogenerated files, but they'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 "Create NSManagedObject subclasses".</div></div></blockquote></span>Xcode has already generated NSManagedObject subclasses for you, so you've now created duplicate classes. That's why you'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"><unknown>:0: error: filename "PHAudioFile+CoreDataClass.<wbr>swift" used twice: </div></div></div></blockquote><br></div></span><div>TL;DR: Don't create NSManagedObject subclasses manually—they'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 <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> 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 "Class Definition" 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 "Create NSManagedObject subclasses". 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"><unknown>:0: error: filename "PHAudioFile+CoreDataClass.<wbr>swift" used twice: '/Users/jdmuys/Phoenix/<wbr>PHAudioFile+CoreDataClass.<wbr>swift' and '/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'</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"><unknown>: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 "</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>" line:</div><div><br></div><div>"Invalid redeclaration of <span style="font-family:menlo;font-size:11px">PHAudioFile</span>"</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>"'<span style="font-family:menlo;font-size:11px">PHAudioFile</span>' is ambiguous for type lookup in this context"</div><div><br></div><div>and of course every line thereafter breaks too.</div><div><br></div><div>Searching for '<span style="font-family:menlo;font-size:11px">PHAudioFile</span>' in my Xcode project, finds only those two files. In particular I can't find any other declaration for '<span style="font-family:menlo;font-size:11px">PHAudioFile</span>'.</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>