Xcode 8 generates broken NSManagedObject subclasses for iOS 10

后端 未结 22 835
栀梦
栀梦 2020-11-27 11:13

I updated my iOS app project recently to iOS 10. Now I\'m trying to change the Core Data Model of my app but the new NSManagedObject subclasses which Xcode generates are bro

相关标签:
22条回答
  • 2020-11-27 12:04

    I found this Post from David Atkinson which is helpful in some way. If I generate the code the way David described. I just get the code with some Syntax errors and if I fix the errors everything works like before. There are no missing files starting with '.' any more.

    The syntax errors i Have to correct are - the unnecessary import - and some public properties which are not intended to be public in my code

    0 讨论(0)
  • 2020-11-27 12:05

    If you have a legacy app and you wish to keep adding managed object classes manually

    1. Make sure your core data model codegen is set to Manual/None
    2. Select your core data model file
    3. Create managed object subclass

    0 讨论(0)
  • 2020-11-27 12:06

    Delete the 3rd import statement because it's empty.

    Note: I don't know why this happens but I guess it's a bug in Xcode 8. Just delete it and it will work fine.

    0 讨论(0)
  • 2020-11-27 12:06

    I think it is a xcode issue, where xcode generates wrong syntax for core data category class. I am creating a nsmanageobjectsubclass for one entity AgentDetails

    Here xcode create wrong code structure in AgentDetails+CoreDataClass.h and AgentDetails+CoreDataClass.m. Those have a code structure like:

    And

    So it is having duplicate interface issue as AgentDetails.h have same interface.

    Now to fix this you have to change the code in AgentDetails+CoreDataClass.h

    and AgentDetails+CoreDataClass.m like this:

    0 讨论(0)
  • 2020-11-27 12:07

    Try to set CodeGen: Manual/None Module: Current Product Module

    It worked for me well, when I faced with the same problem.

    0 讨论(0)
  • 2020-11-27 12:07

    You can try these steps

    1. Select the .xcdatamodeld file in Xocde Project Navigator
    2. In the Data Modul Inspector, make sure Codegen : Manual/None
    3. Then Edit -> Create NSManagedObject Subclass
    4. Clean product and rebuild

    Is that work? If not

    Make sure you all class has not the same name with Entities. You can find these class in Build Phases -> Compile Sources. Rename the class or Entities if they duplicated

    Or

    You can run this command to in your project folder to get more error info

    xcodebuild -verbose

    I got this message when i have this problem

    duplicate symbol _OBJC_CLASS_$_RandomList in:

    xxxx/RandomList.o

    xxxx/RandomList+CoreDataClass.o

    RandomList.h and RandomList+CoreDataClass.h have a same symbol when compiling

    I think that why Xcode did not warn you, but Compiler will throw error

    Hope this will help you

    0 讨论(0)
提交回复
热议问题