Invalid Redeclaration in Auto Code Generate Nsmanagedobject Subclass Swift 3

invalid redeclaration in auto code generate NSManagedObject Subclass Swift 3

In Xcode 8.1, before using the auto code generator, you must select the entity in your data model:

Entity

Then go to the Data Model Inspector tab:

Data Model Inspector

Under "Codegen" select "Manual/Node"

After that you could create a NSManagedObject subclass without errors.


Alternatively, if you have already used 'Class Definition', you can go into your existing .xcdatamodeld file and set all current entities to 'Manual/None' under Codegen. Make sure to save your project (File -> Save), delete your existing Derived Data, clean the project, and then build. Resolved it for me without having to re-make my whole model.

Errors after 'Create NSManagedObject Subclass for CoreData Entities

The current default in Xcode is to automatically create subclasses of NSManagedObject for you in the /Users/<your user name>/Library/Developer/Xcode/DerivedData/AppName-agkwmibzbo‌​pevjgfajlcbyixzyev/B‌​uild/Intermediates/A‌​ppName.build/Debug-i‌​phonesimulator/AppNa‌​me.build/DerivedSour‌​ces/CoreDataGenerate‌​d/Modeldirectory; The DerivedData directory is where Xcode saves automatically generated code. You are redeclaring the same subclass by doing Editor>Create NSManagedObject Subclass... that is why you are getting the "Invalid redeclaration of 'UserRoutine' 'UserExercise' is ambiguous for type lookup in this context @NSManaged only allowed on an instance property or method" error. To resolve the errors and manually create a subclass of NSManagedObjects what you need to do is:

  1. Open terminal and navigate to /Users/<your user name>/Library/Developer/Xcode/DerivedData/AppName-agkwmibzbo‌​pevjgfajlcbyixzyev/B‌​uild/Intermediates/A‌​ppName.build/Debug-i‌​phonesimulator/AppNa‌​me.build/DerivedSour‌​ces/CoreDataGenerate‌​d/Model

  2. Run this command: rm -rf * (now be careful with this command, run it only when you get to the final directory where the generated codes are or you'll break your project for good)

  3. Delete your current data model

  4. Create a new data model

  5. Select your new data model's entity (do this for each entity within the data model) and go to its attributes inspector and set its Codegen to Manual/None Before the first run after you have created a new data model.

  6. Create a subclass of NSManagedObject by going to Editor>Create NSManagedObject Subclass...

Your errors should disappear.

Hope this helped!

Subclassing NSManagedObject with swift 3 and Xcode 8 beta

It's probably a (beta) clash with the new automatic subclass generation, which can be controlled in the entity inspector of the data model file.

From the documentation (What's New In Core Data)

Xcode automatic subclass generation


Xcode now supports automatic generation of NSManagedObject subclasses
in the modeling tool. In the entity inspector:

  • Manual/None is the default, and previous behavior; in this case you
    should implement your own subclass or use NSManagedObject.
  • Category/Extension generates a class extension in a file named like
    ClassName+CoreDataGeneratedProperties. You need to declare/implement
    the main class (if in Obj-C, via a header the extension can import
    named ClassName.h). -
  • Class Definition generates subclass files named
    like ClassName+CoreDataClass as well as the files generated for
    Category/Extension.

The generated files are placed in DerivedData and
rebuilt on the first build after the model is saved. They are also
indexed by Xcode, so command-clicking on references and fast-opening
by filename works.

Invalid redeclaration of 'viewWillTransition(to:with:)' in swift 3

Invalid redeclaration of viewWillTransition(to:with:)

It means by mistake you have added viewWillTransition method twice in your Controller remove one of it will solved the error.

Xcode NSManagedObject subclass auto-generation to overwrite existing files in separate groups

No, you're not overlooking any command. Xcode has a different idea of how to organize things than you do. For problem 1, that's just how it is. Xcode won't attempt to locate existing files in your project when re-generating them. Maybe it should, but that's not how it's designed right now.

How to auto generate NSManagedObject subclasses with date attribute as Date instead of NSDate?

It's not currently possible, because Core Data is still very much tied to Objective-C types, and this is one of the places it shows.

However, you can still assign a Date to an NSDate attribute:

    newEvent.timestamp = Date() as NSDate

It's far from ideal, but if you have other code that uses Date, you don't have to make it use NSDate instead. Use as to convert only when working directly with your managed objects.



Related Topics



Leave a reply



Submit