Xcode-beta 8. Can't create core data

前端 未结 9 1340
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 09:06

I have been trying to add core data. And every time I got the same error:

error: filename \"EntityName +CoreDataClass.swift\" used twice: \'/Users/userName/         


        
9条回答
  •  余生分开走
    2020-12-13 09:41

    I'm actually having the same problem (using Swift) and suspect it is a bug. If I understand correctly the OP is using Xcode's autogen NSManagedObject subclasses and is not then subsequently creating additional (superfluous) subclasses which appears to be a source of some confusion.

    Steps to reproduce:

    1. Create a new project, single view application. Tick "Use Core Data'

    2. Create an entity in the model entity, add properties, ensure file is saved (sometimes Xcode 8 Beta throws the data if not explicitly saved)

    3. Select Editor -> Created NSManagedObject subclass. Tick relevant boxes

    Xcode creates 3 files:

    1. COREDATA_DATAMODELNAME_+CoreDataModel.swift. This file is corrupted and contains non-valid entries following statements to import Foundation and CoreData - the project will not compile unless this file is deleted

      import Foundation
      
      import CoreData
      
      ___COREDATA_DATAMODEL_MANAGEDOBJECTCLASSES_IMPLEMENTATIONS___
      
    2. EntityName+CoreDataClass.swift

    3. EntityName+CoreDataProperties.swift

    Although the editor doesn't flag any errors at this point, attempts to compile fail for the reasons listed by the OP (namely missing files with the same names but with a '.' prefix in the DerivedData folder)

    If you create the NSManagedObject subclasses manually after creating your model without using Xcode's evidently bugged auto-gen, there are no issues. A bit more typing but a lot more reliable! However, you will need to start from a 'clean' project (i.e. before you attempted to auto-generate the subclasses) otherwise the error persists. Cleaning out Derived Data won't help sadly.

    ***** UPDATED ***** There does appear to be something rather odd going on and there does appear to be silent code generation as originally suggested (apologies) but this is very different behaviour from what one would expect. Furthermore, this code is not visible in the editor (which seems a little pointless as well as confusing). It is created in a subfolder of DerivedData > Build > Intermediates > .Build.

    I can completely see why the OP was confused (as was I!) For what it's worth this 'feature' is undoubtedly an attempt to be helpful but is somewhat confusing if you're used to previous behaviour and you are offered an option to generate a visible and editable duplicate from the main menu.

    So, select 'Manual/None' in the Codegen window (shown below) and then you can either use the auto-gen option in the menu bar (after deleting the 'junk') or write your own code.

提交回复
热议问题