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:
Then go to the Data Model Inspector tab:
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-agkwmibzbopevjgfajlcbyixzyev/Build/Intermediates/AppName.build/Debug-iphonesimulator/AppName.build/DerivedSources/CoreDataGenerated/Model
directory; 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:
Open terminal and navigate to
/Users/<your user name>/Library/Developer/Xcode/DerivedData/AppName-agkwmibzbopevjgfajlcbyixzyev/Build/Intermediates/AppName.build/Debug-iphonesimulator/AppName.build/DerivedSources/CoreDataGenerated/Model
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)Delete your current data model
Create a new data model
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.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 useNSManagedObject
.- 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
likeClassName+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
How to Properly Animate Uiscrollview Contentoffset
Xcode 4.3:Missing Icons for iOS Apps in Organizer's Archives
Reused Cells in a Uicollectionview Show Multiple Uiimageviews When They Should Only Show One
Uiimagejpegrepresentation Has Been Replaced by Instance Method Uiimage.Jpegdata(Compressionquality:)
How to Write Application Logs to File and Get Them
Programmatically Creating Uilabel
How to Wait for a Function to End on iOS/Swift, Before Starting the Second One
Cannot Run Application on Simulator After Installing Xcode 11 - Cfbundleversion Error
What Is Main Thread Checker in Xcode
How to Check If the iOS Device Is Locked/Unlocked Using Swift
Delete Cell from Uicollectionview Without Reloading from Top
iOS 10 Heading Arrow for Mkuserlocation Dot
Clipstobounds Causes Uiimage to Not Display in iOS10 & Xcode 8
Swift Add Footer View in Uitableview
Generating Custom Thumbnail from Alassetrepresentation
_Unused Flag Behavior/Usage (Gcc with Objective-C)
To Change the Color of Unselected Uitabbar Icon in iOS 7
Uicontroleventeditingchanged Doesn't Get Fired When Using Settext of Uitextfield