1

Every time I add NSManagedObject subclass to a vanilla app (with CoreData enabled) or to a vanilla app without CoreData enabled at the start but added after, Xcode (10.2.1) / Swift (4.2) is throwing up 3 errors.

I'm trying to create a simple application in Xcode v10.2 (have just updated to 10.2.1) that uses Core Data. I have tried to do this by two methods ie. starting a brand new app and ensuring Core Data is ticked, and also starting a vanilla app without Core Data ticked and then adding Core Data. The issue I'm having is occurring after I create an entity and some entity attributes (everything compiles fine up to that point every time), however the issue occurs as soon as I go to add NSManagedObject subclass from the Editor dropdown.

As soon as I've added NSManagedObject, Xcode reindexes and I get 3 errors, two stating that "Multiple commands produce...." and another one that states Command CompileSwiftSources failed with a nonzero exit code.

I've tried to recreate the NSManagedObject, however that makes no difference. I have followed the instructions to add a build statement (SWIFT_ENABLE_BATCH_MODE set to NO), but it makes no difference.

I'm not trying to do anything fancy here, just get to a point where I have NSManagedObject subclass enabled as part of CoreData so that I can get on and write the rest of my app on Xcode 10.2/Swift 4.2.

Also I have just updated to Xcode 10.2.1 which has made no difference ie. problem still occurs when you try and add the NSManagedObject subclass.

Any ideas anyone?

Screen shot of compiler errors

  • You don't say what the multiple commands are producing but see if the 2nd answer here is useful: https://stackoverflow.com/questions/50718018/xcode-10-error-multiple-commands-produce – Phillip Mills Apr 25 '19 at 00:42
  • Hi Phillip, thanks for the links. The 3rd answer helps in that it hides 2 of the errors if I set the compilation to legacy, however, I don't really want to do that as it is masking the real issue (which looks like a bug in Xcode to me). – James Leitch Apr 25 '19 at 04:08
  • Woohoo - I've found the answer !!! The key is searching for the error on stack overflow for 'Build fails with "Command failed with a nonzero exit code" ' and within those answers there is a post from JeffreyWang23 on Sep16'18 that fixes this. Am trying to include the link but I just followed that advice to delete the Entity+CoreDataClass.swift and Entity+CoreDataProperties.swift from within Xcode, then under "class" of the entity model inspector, change "module" to Current Product Module and "codegen" to Manual/None, then recreate NSManagedObject. All the errors then disappeared ! :) :) :) – James Leitch Apr 25 '19 at 04:36
  • Link to resolution: https://stackoverflow.com/a/52357296/11407686 (All credit to the authors of the other article). :) – James Leitch Apr 25 '19 at 04:44

2 Answers2

3

I've found the answer !!! The key is searching for the error on stack overflow for 'Build fails with "Command failed with a nonzero exit code" ' and within those answers there is a post from JeffreyWang23 on Sep16'18 that fixes this.

Link to resolution: stackoverflow.com/a/52357296/11407686 (All credit to the authors of the other article).

I just followed that advice to delete the Entity+CoreDataClass.swift and Entity+CoreDataProperties.swift from within Xcode, then under "class" of the entity model inspector, change "module" to Current Product Module and "codegen" to Manual/None, then recreate NSManagedObject.

All the errors then disappeared ! :) :) :)

jessi
  • 1,438
  • 1
  • 23
  • 36
2

for solve this issue you should Select the xcdatamodeld file in the project navigator, select the entity and press ⌥⌘3 (Data Model Inspector).

If you created the class manually the Codegen popup must be set to Manual/None otherwise the class file is created implicitly.

refer to this answer

enter image description here

mohsen
  • 4,698
  • 1
  • 33
  • 54