Duplicate symbol error when adding NSManagedObject subclass, duplicate link

后端 未结 6 1557
情深已故
情深已故 2020-12-13 13:02

I was trying to create NSManagedObject subclasses (2 related entities) automatically in Xcode. They are generated like this:

6条回答
  •  心在旅途
    2020-12-13 13:50

    Edit: Thanks to some help from @iPeter, found the following:

    After doing Editor > Generate NSManagedObject files, if you trash the files BEFORE building, your project should build no problems.

    Then #import "myManagedObjectName+CoreDataClass.h" (where the MO name is the one in the entity inspector in core data) into any classes where you require those Managed Objects.

    In other words, you don't require any of the actual ManagedObject files in your folder. Xcode keeps the generated ones in your Derived Data folder.

    If for some reason you need those files to remain in your file directory, the following workaround will work. Go to your Target and delete the CoreDataClass sources in your Compile Sources.

    Leaving you with this:

    • Most of the new attributes / relationships I added after the initial generation of ManagedObject subclasses were available as properties after a build. In one case where I renamed an existing relationship, I had to do Editor > Generate NSManagedObject Subclasses again, then I trashed the new files in my folder, built, and everything worked OK.

    Just wrote a blog post that includes this info for anybody interested.

提交回复
热议问题