2

I am using Xcode 8.2.1. I am also using CoreData in my project. When I try to generate a build or when I archive I am seeing the following error. Files mentioned in the error also changes at times.

ERROR:

<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/BuildingRoofMapping+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/BuildingRoofMapping+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/Region+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/Region+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/StateRegionMapping+CoreDataProperties.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/WalkingDoors+CoreDataClass.swift'
<unknown>:0: error: no such file or directory: '/Users/anuragparashar/Library/Developer/Xcode/DerivedData/app-drgjxhipxxqdrcatqfdgpayyxnud/Build/Intermediates/app.build/Debug-iphoneos/app.build/DerivedSources/CoreDataGenerated/app/WalkingDoors+CoreDataProperties.swift'
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

Here is how my CoreData Entities are configured:

enter image description here

Things I have Tried:

  1. Check the location to see if files are actually missing, Files where present exactly at the same path.
  2. I cleaned the build folder and removed derived data and build it again. Nothing helped.
  3. Tried all the answers in this link. Nothing Worked.
  4. Accepted Answer of this question doesn't seem to work either.

I am not sure why this error is coming. Any help is appreciated

EDIT

If I completely remove CoreData from my code then it Archives Successfully.

EDIT 2 :

When I change CodeGen to Manual/None and add files manually as suggested by @Anil . It builds successfully, But when I try to fetch the CoreData entity using :

let context = appDelegate.persistentContainer.viewContext
let buildingRoofMapping = BuildingRoofMapping(context:context)

It gives me run time error. Error :

'NSInvalidArgumentException', reason: 'An NSManagedObject of class 'BuildingRoofMapping' must have a valid NSEntityDescription.'

EDIT 3: Sample Code link. Run it in simulator. It crashes in fetchBasicPrice() of ViewController.swift file

Community
  • 1
  • 1
Priyal
  • 879
  • 1
  • 9
  • 30
  • https://www.google.co.in/search?q=Command+%2FApplications%2FXcode.app%2FContents%2FDeveloper%2FToolchains%2FXcodeDefault.xctoolchain%2Fusr%2Fbin%2Fswiftc+failed+with+exit+code+1&rlz=1C5CHFA_enIN720IN720&oq=Command+%2FApplications%2FXcode.app%2FContents%2FDeveloper%2FToolchains%2FXcodeDefault.xctoolchain%2Fusr%2Fbin%2Fswiftc+failed+with+exit+code+1&aqs=chrome..69i57j69i60.443j0j7&sourceid=chrome&ie=UTF-8#q=swiftc+failed+with+exit+code+1+xcode+8.2&* – iPatel Apr 03 '17 at 06:47
  • @iPatel thanks for the link. But before commenting please read what I have already tried and what you are suggesting me. – Priyal Apr 03 '17 at 06:50
  • Set the module to `Current Product Module`. – vadian Apr 03 '17 at 06:56
  • @vadian setting it to Current Product Module doesn't work. – Priyal Apr 03 '17 at 08:02
  • Is this the complete error? Because I wonder that `BuildingRegionMapping` is not mentioned in the error. – shallowThought Apr 03 '17 at 08:08
  • @shallowThought, Yes its complete error. I added ScreenShot for a sample entity. All of my entities are configured in the same manner. Also files mentioned in error keep on changing. – Priyal Apr 03 '17 at 08:09
  • Means `BuildingRegionMapping` is also mentioned in the error "sometimes" ? – shallowThought Apr 03 '17 at 08:11
  • Maybe. I am not sure, because at times it lists 10 - 12 files so it is difficult to remember all the files. But I am sure that all the files have same configuration. – Priyal Apr 03 '17 at 08:16
  • @shallowThought I don't think files have any connection with the this issue. – Priyal Apr 03 '17 at 09:32

4 Answers4

4

I'll tell you what I have faced the same issue. In my case from Xcode 8 CoreData creates NSManagedObject class files in documents directory. I am sure you must have also created the same NSManagedObject files by your own.

You need to do following changes .xcdatamodel and regenerate a build. I have attached image below.

Make a change in Module and set it to Current Product Module and change the Codegen to Manual/None.

Let me know if you have more questions.

enter image description here

Anil Kukadeja
  • 1,348
  • 1
  • 14
  • 27
1

Below steps worked for me:

  1. Change Module to Current Product Module and Codegen to Manual/None as suggested in Anil's Answer, for ALL the entities.
  2. Manually Create CoreData files. For every entity two files are created.

    • One will be EntityName+CoreData with below contents :

          import Foundation
          import CoreData
      
          public class EntityName: NSManagedObject {
          }
      
    • another will be named : EntityName+Properties

      import Foundation
      import CoreData
      
      extension BasicPrice {
           @nonobjc public class func fetchRequest() -> NSFetchRequest<BasicPrice> {
           return NSFetchRequest<BasicPrice>(entityName: "BasicPrice");}
      
         @NSManaged public var var1 : String?
         @NSManaged public var var2 : Int32
         @NSManaged public var var3 : Float
         @NSManaged public var var4 : Bool
       }
      

NOTE: This kind of class/structure is not my developed, it is followed by CoreData internally when we select Class Definition from CodeGen.

Hope it helps someone!

Community
  • 1
  • 1
Priyal
  • 879
  • 1
  • 9
  • 30
  • Today faced same issue but in my case I just do "Command+Shift+k" 2-3 time and problem was solve. – iPatel Apr 04 '17 at 13:54
0

First, If you are checking or running the code in simulator and on changes in coreData code you are getting crashed, then you need to delete the app from the simulator and then again install and run. By doing this, changes that are made in your code do not make crash or show error.

Gourav Joshi
  • 2,419
  • 2
  • 27
  • 45
  • Code is not crashing on simulator. I am facing error while generating a build, If I simply run on simulator everything works perfectly. – Priyal Apr 03 '17 at 06:54
  • After removing the build + Cleaning Build folder + removing derived data and then trying to build it again also results in the same error. – Priyal Apr 03 '17 at 06:55
0

I am writing it as an answer because I am not allowed to comment yet. From your comments I have assumed that you have cleaned the derived folder as well as deleted the app from simulator as well as from device while building on it.

Did you try setting Build Active Architecture Only flag to No in the Project settings tab? If not please do that as well.

While archiving, the app will be built for all targets. And thus some issue might surface which you would have missed by setting the flag to Yes during development.

saugat gautam
  • 324
  • 2
  • 8
  • It doesnt help. :( – Priyal Apr 03 '17 at 09:58
  • I see. Try to select the whole project and not just a target while changing the flag. Also, Did you check that all of your coredata related files are linked to your target? You can check this by selecting a file and then look in the file inspector (Cmd + alt + 1). – saugat gautam Apr 03 '17 at 15:44